RGdoi

Detect DOIs as hyperlinks

当前为 2018-03-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RGdoi
  3. // @namespace https://www.researchgate.net
  4. // @description Detect DOIs as hyperlinks
  5. // @include http://www.researchgate.net/publication/*
  6. // @include https://www.researchgate.net/publication/*
  7. // @version 0.0.4a
  8. // @grant GM.xmlHttpRequest
  9. // ==/UserScript==
  10.  
  11. // TODO: Modify regexp to work after logging in.
  12.  
  13. var matchRegexpGlobal = /DOI:.*/mg;
  14. var extractRegexp = /(?:DOI:\s)([\w\.\/\-])*/g;
  15.  
  16. function extractDoiAndHyperlink(text)
  17. {
  18. var root = "https://doi.org/";
  19.  
  20. // var text = window.document.body.textContent;
  21. while((match = matchRegexpGlobal.exec(text)) != null) {
  22. var doi = extractRegexp.exec(match[0]);
  23. if (doi != null) {
  24. var doi_link = doi[0].replace(/DOI\:\s/i, "");
  25. replaceElement(doi_link);
  26. }
  27. }
  28. }
  29.  
  30.  
  31. function replaceElement(doi) {
  32. var divs = document.querySelectorAll(".publication-meta-secondary");
  33. var element = divs[0];
  34. var replace = '<a href="https://doi.org/' + doi +'">' + element.innerHTML + '</a>';
  35. element.innerHTML = replace;
  36. }
  37.  
  38. // Old method: which gets blocked
  39. // extractDoiAndHyperlink(window.top)
  40.  
  41. GM.xmlHttpRequest({
  42. method: "GET",
  43. url: location.href,
  44. headers: {
  45. "Content-Type": "application/x-www-form-urlencoded"
  46. },
  47. onload: function(response) {
  48. extractDoiAndHyperlink(response.responseText);
  49. }
  50. });