qutebrowser: Add documentation to doi2scihub script
Added some simple usage explanation to the script.
This commit is contained in:
parent
6bc582f67a
commit
b4ec0b9e0a
1 changed files with 23 additions and 12 deletions
|
@ -2,16 +2,26 @@
|
||||||
"""
|
"""
|
||||||
Goes to the sci-hub page for the current article, based on DOI.
|
Goes to the sci-hub page for the current article, based on DOI.
|
||||||
|
|
||||||
Can be invoked with DOI on a page selected,
|
|
||||||
through the hinting mode when selecting a DOI link
|
|
||||||
or on a publisher page (any page where doi meta-tags are set) -
|
|
||||||
works on ScienceDirect, Taylor&Francis, Springer, etc.
|
|
||||||
|
|
||||||
Updates its sci-hub link based on the one listed on sci-hub wiki page.
|
|
||||||
|
|
||||||
Based on the work in
|
Based on the work in
|
||||||
https://github.com/cadadr/configuration/blob/4b6a241d04d113f322b960890a0d0a0ab783a7b3/dotfiles/qutebrowser/userscripts/doi
|
https://github.com/cadadr/configuration/blob/4b6a241d04d113f322b960890a0d0a0ab783a7b3/dotfiles/qutebrowser/userscripts/doi
|
||||||
with much gratitude.
|
with much gratitude.
|
||||||
|
|
||||||
|
The program can be invoked with DOI on a page selected, through the hinting mode when selecting a DOI link or on a publisher page (any page where doi meta-tags are set) - works on ScienceDirect, Taylor&Francis, Springer, etc.
|
||||||
|
That means you can give it a doi through a link or on the current page, for example with the following mappings:
|
||||||
|
|
||||||
|
```python
|
||||||
|
config.bind('"p', "spawn --userscript doi2scihub")
|
||||||
|
config.bind(';p', "hint links userscript doi2scihub")
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also pass the doi as the (only) argument to the userscript:
|
||||||
|
|
||||||
|
```
|
||||||
|
:spawn --userscript doi2scihub https://doi.org/10.37394/23207.2021.18.68
|
||||||
|
`
|
||||||
|
|
||||||
|
Updates its sci-hub link based on the one listed on sci-hub wiki page.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +36,6 @@ mode = os.getenv("QUTE_MODE")
|
||||||
|
|
||||||
text = None
|
text = None
|
||||||
|
|
||||||
|
|
||||||
class DoiTagParser(html.parser.HTMLParser):
|
class DoiTagParser(html.parser.HTMLParser):
|
||||||
doi = None
|
doi = None
|
||||||
|
|
||||||
|
@ -62,13 +71,17 @@ def get_scihub_url(wiki_page: str = "https://wikiless.org/wiki/Sci-Hub"):
|
||||||
return parser.current or "https://sci-hub.ru"
|
return parser.current or "https://sci-hub.ru"
|
||||||
|
|
||||||
|
|
||||||
if mode == "hints":
|
# use doi argument if we got one
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
text = sys.argv[1]
|
||||||
|
# use the hinted url
|
||||||
|
elif mode == "hints":
|
||||||
text = os.getenv("QUTE_URL", "").strip()
|
text = os.getenv("QUTE_URL", "").strip()
|
||||||
|
# use the current selection
|
||||||
elif mode == "command" and os.getenv("QUTE_SELECTED_TEXT"):
|
elif mode == "command" and os.getenv("QUTE_SELECTED_TEXT"):
|
||||||
text = os.getenv("QUTE_SELECTED_TEXT", "").strip()
|
text = os.getenv("QUTE_SELECTED_TEXT", "").strip()
|
||||||
|
# just try to find a doi on current page
|
||||||
elif os.getenv("QUTE_HTML"):
|
elif os.getenv("QUTE_HTML"):
|
||||||
# TODO implement html source-based doi search for current page here
|
|
||||||
# use python htmlparser and find metatags: e.g. citation_doi, dc.identifier
|
|
||||||
with open(os.getenv("QUTE_HTML", ""), "r") as source:
|
with open(os.getenv("QUTE_HTML", ""), "r") as source:
|
||||||
parser = DoiTagParser()
|
parser = DoiTagParser()
|
||||||
parser.feed(source.read())
|
parser.feed(source.read())
|
||||||
|
@ -92,7 +105,6 @@ with open(os.getenv("QUTE_FIFO", ""), "w") as fifo:
|
||||||
)
|
)
|
||||||
|
|
||||||
match = doi_re.match(text)
|
match = doi_re.match(text)
|
||||||
|
|
||||||
if match is None or match["meat"] is None:
|
if match is None or match["meat"] is None:
|
||||||
fifo.write(
|
fifo.write(
|
||||||
f"message-warning \"'{text}' is probably not a DOI, or update regexp\""
|
f"message-warning \"'{text}' is probably not a DOI, or update regexp\""
|
||||||
|
@ -101,5 +113,4 @@ with open(os.getenv("QUTE_FIFO", ""), "w") as fifo:
|
||||||
else:
|
else:
|
||||||
url = get_scihub_url()
|
url = get_scihub_url()
|
||||||
doi = match["meat"]
|
doi = match["meat"]
|
||||||
|
|
||||||
fifo.write(f"open -t {url}/{doi}")
|
fifo.write(f"open -t {url}/{doi}")
|
||||||
|
|
Loading…
Reference in a new issue