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.3
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. function rgdoi()
  13. {
  14. openDoi(window.top)
  15. }
  16.  
  17. var matchRegexpGlobal = /DOI:.*/mg;
  18. var extractRegexp = /(?:DOI:\s)([\w\.\/\-])*/g;
  19.  
  20. function openDoi(win)
  21. {
  22. var root = "https://doi.org/";
  23.  
  24. var text = win.document.body.textContent;
  25. while((match = matchRegexpGlobal.exec(text)) != null) {
  26. var doi = extractRegexp.exec(match[0]);
  27. if (doi != null) {
  28. var doi_link = doi[0].replace(/DOI\:\s/i, "");
  29. alert('DOI detected');
  30. replaceElement(doi_link);
  31. }
  32. }
  33. for (var i = 0, n = win.frames.length; i < n; i++)
  34. openDoi(win.frames[i]);
  35. }
  36.  
  37.  
  38. function replaceElement(doi) {
  39. var divs = document.querySelectorAll(".publication-meta-secondary");
  40. var element = divs[0];
  41. var replace = '<a href="https://doi.org/' + doi +'">' + element.innerHTML + '</a>';
  42. element.innerHTML = replace;
  43. }
  44.  
  45.  
  46. rgdoi()