diff --git a/qutebrowser/.local/share/qutebrowser/userscripts/doi2scihub b/qutebrowser/.local/share/qutebrowser/userscripts/doi2scihub index 5f47a84..5900eac 100755 --- a/qutebrowser/.local/share/qutebrowser/userscripts/doi2scihub +++ b/qutebrowser/.local/share/qutebrowser/userscripts/doi2scihub @@ -2,16 +2,26 @@ """ 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 https://github.com/cadadr/configuration/blob/4b6a241d04d113f322b960890a0d0a0ab783a7b3/dotfiles/qutebrowser/userscripts/doi 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 - class DoiTagParser(html.parser.HTMLParser): 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" -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() +# use the current selection elif mode == "command" and os.getenv("QUTE_SELECTED_TEXT"): text = os.getenv("QUTE_SELECTED_TEXT", "").strip() +# just try to find a doi on current page 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: parser = DoiTagParser() parser.feed(source.read()) @@ -92,7 +105,6 @@ with open(os.getenv("QUTE_FIFO", ""), "w") as fifo: ) match = doi_re.match(text) - if match is None or match["meat"] is None: fifo.write( 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: url = get_scihub_url() doi = match["meat"] - fifo.write(f"open -t {url}/{doi}")