DOI-Unlock

DOI-Unlock with CTRL+left click on any DOI on any page will turn to 3 buttons, which are linked to Sci-Hub, Lib-Gen and Z-Lib

  1. // ==UserScript==
  2. // @name DOI-Unlock
  3. // @namespace https://greasyfork.org/en/users/738719-szmegma
  4. // @version 1.0.6
  5. // @description DOI-Unlock with CTRL+left click on any DOI on any page will turn to 3 buttons, which are linked to Sci-Hub, Lib-Gen and Z-Lib
  6. // @author szmegma
  7. // @match http://*/*
  8. // @match https://*/*
  9. // @require https://code.jquery.com/jquery-latest.min.js
  10. // @license MIT
  11. // @grant GM_addStyle
  12. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAACAVBMVEUAAADYiwvZpxGjo6OkpKSkpKTZnxCjo6OioqLZoxDZmw/Zlg7ZlA7Zjgyjo6OkpKSlpaWjo6PZkQ2kpKSkpKTZmg7YkQ2kpKSjo6Ojo6Ojo6Ojo6Ojo6OoqKixsbHapxLZnQ/YpxGjo6PZjAykpKTZpxDZjQzViwmjo6PZpRHZpRHLpTjYjgzZjgykpKTVphujo6PZphHWphGjo6OlpaX///8AAAC9vb3/pAD/vgb/uwb/uQXjkgn/oQDqsQ3/tgS7u7v/rwO8vLylpaX/tAT/pQGtra3/qwKqqqr/5a//68Kurq7/rAO2trb3twj3oAL//fqzs7Onp6f3rQXuqgMDAQD/+/P/7MH/uSX2sAb/qAT3pAT/sAOfbwL/9N7/7sn/35v/vTv3swepdAP0pgKfaQAoGwAJBgD/89j/137Or1P/y1H/uxX3qASfcwP4ogJaQgKyeQHYjABtSAAbEwD/8M24uLisrKz/6Kr/1nf/0HT/1XD/ymn/xFn/wlHGp0z/x0KfgD//xi+fdBv/uBDnsA7/qw7vtAvrlwb/swTmnQSIXQTNjgLKhwHmlQClawD//PX/9uH/79H/6rj/56//5Kf/1or/2oT/1G7/xE//v0T/vEP7uiD/tCDbnATBjQTzqgOfcQKNZAJ0UgFbQAHwnACTXwB7UQBCKwA0JQAYEADQdliYAAAANXRSTlMAcZ3+jxn1bzn19fX19IpiFvf1kgn19fLguJtyQA8E/PWSeWZUPTwb69nY1MzKwaelWVlLKPS7cy4AAAKKSURBVEjH3dLnW9pAHMBxW9TWAUirdYJbu3dSq21RSMCKgAyRaYuIA2hBcO9aZ+vo3nu3f2V/B3l44LnkOt+03xeBJPdJ7u5Jxl+psEK6h0taIf8JkFVWrG5PppadPPsjIS1u16vOJVPpJ2TlZFEuMgFIS6+WkMQZkT7+bK6EHldLCQsvMcGQVp1ZzWXWtcIF00G58ELMKjSR0rq9XHWl6nF4qVl4OaU6uJ8+9Uz0FNNxQVKsh9slitRLCjRXvUwhIOQimLmuLP1imQ5WJyoQIAVxsj/9YqYGkax/jRTKJjQacw2B4FVIJJKaQn5C7D8g9dW7+TqyEAgEFk5U1+PidOXKJUIrlacwcnjtPLG1QxjJMZCJIYeHNBMjEkckEnmdNnxpcnKJh2T3tXBZaZq+3pJS8xBF3TVk/woJUdALPqLkihNlaj0UNdbHQxwMw7zyvPNZEXkLJ8rFJzPBZQYKTQ2HHDipcjDWD90wevA9HDwME+ylINtjJcM8tNnuO6owkmt585VO5tmYobh6ljcewNGSy0NiNDQwkCCLFNQ71gXHq+7L/KTo1iBNj2663ZujiFyhqDtBt9sOv112IeKDkSNt0Aj8uQlPH0YndnjPFJAOSxFG8m7TdHc/GtUPm3ADiLcNNQQzQ+RangDphJKkE0Ug+WhiPi2UnBg6QRObFiJo+d+2tNottHw/LNv2VKt9mVg+EFc+TlyfUzbZ/yy+yffim+wUIAdc4S90Mr9zmuLqWE2QfTgJs8ZY/IOJIcKy84kP5pGTZREJ8xAjy7LbO592tpui0ehHOHF6Z2fnV1nIOzf33IgTsbGJ2O8QMUaOrV8ktn4UIw3iC8TEDRlYjbW7CNU2ZvxB3wGnnimlJ4uJUAAAAABJRU5ErkJggg==
  13. // ==/UserScript==
  14.  
  15. //================================================== settings
  16.  
  17. //variables
  18. const
  19. regex = '(10\.[0-9]{4,}(?:\.[0-9]+)*/(?:(?![%"&\'<>#? ])\\S)+)',
  20. doiRegex = new RegExp('(?:' + regex + ')', 'i'),
  21. //doiRegex = new RegExp(regex),
  22. btn1 = document.createElement('input'),
  23. btn2 = document.createElement('input'),
  24. btn3 = document.createElement('input'),
  25. libgenURL = 'http://libgen.li/scimag/index.php?s=',
  26. zlibURL = 'https://booksc.org/s/?q=',
  27. scihubURL = 'https://sci-hub.ru/',
  28. style = "color:orange;font-size:1.5rem;line-height:2;padding:5px;background:black;text-shadow: 1px 1px 0 black, 1px -1px 0 black, -1px 1px 0 black, -1px -1px 0 black";
  29.  
  30. //================================================== find DOI
  31. function findDOI(element){
  32. if($(element).is("[href*='org/10.']"))
  33. return $(element).attr("href").split('org/')[1].trim();
  34. if($(element).text().match(doiRegex)!==null)
  35. return $(element).text().match(doiRegex)[0].trim();
  36. return false;
  37. }
  38.  
  39. //================================================== button click to navigate the selected site
  40. function unlockDOI(){
  41. if($(this).is("[data-doi]")){
  42. if(this.id=='scihub')
  43. window.open(scihubURL+$(this).attr('data-doi'));
  44. if(this.id=='zlib')
  45. window.open(zlibURL+$(this).attr('data-doi'));
  46. if(this.id=='libgen')
  47. window.open(libgenURL+$(this).attr('data-doi'));
  48. }
  49. }
  50.  
  51. $(document).ready(function(){
  52.  
  53. //================================================== set attributes for all buttons
  54. btn1.setAttribute("value", "SCI-HUB");
  55. btn1.setAttribute("type", "button");
  56. btn1.setAttribute("id", "scihub");
  57. btn1.setAttribute("class", "DOI-unlock-button");
  58.  
  59. btn2.setAttribute("value", "Z-LIB");
  60. btn2.setAttribute("type", "button");
  61. btn2.setAttribute("id", "zlib");
  62. btn2.setAttribute("class", "DOI-unlock-button");
  63.  
  64. btn3.setAttribute("value", "LIB-GEN");
  65. btn3.setAttribute("type", "button");
  66. btn3.setAttribute("id", "libgen");
  67. btn3.setAttribute("class", "DOI-unlock-button");
  68.  
  69. //================================================== append buttons to the body and acivate them
  70. document.getElementsByTagName('body')[0].append(btn1,btn2,btn3);
  71. document.getElementById("scihub").addEventListener("click", unlockDOI, false);
  72. document.getElementById("zlib").addEventListener("click", unlockDOI, false);
  73. document.getElementById("libgen").addEventListener("click", unlockDOI, false);
  74.  
  75. //================================================== remove all inspected class and DOI attribute from buttons
  76. //remove all button attributes
  77. $('input').removeAttr('data-doi');
  78.  
  79. //remove all highlights
  80. [].forEach.call(document.querySelectorAll('*'), function(a){
  81. a.classList.remove('DOI-unlock-inspected');
  82. });
  83.  
  84. //================================================== if BACK or FORWARD button has been clicked
  85. if(window.history && window.history.pushState) {
  86. window.history.pushState('forward', null, '');
  87. $(window).on('popstate', function(){
  88.  
  89. //remove all button attributes
  90. $('input').removeAttr('data-doi');
  91.  
  92. //remove all highlights
  93. [].forEach.call(document.querySelectorAll('*'), function(a){
  94. a.classList.remove('DOI-unlock-inspected');
  95. });
  96. });
  97. }
  98.  
  99. //================================================== find DOI press CTRL key and hold + click on DOI
  100. $(document).on('click', function(e){
  101.  
  102. //if NOT the DOI-unlock-button has been clicked
  103. if(!$(e.target).hasClass('DOI-unlock-button')){
  104.  
  105. //remove all button attributes
  106. $('input').removeAttr('data-doi');
  107.  
  108. //remove all highlights
  109. [].forEach.call(document.querySelectorAll('*'), function(a){
  110. a.classList.remove('DOI-unlock-inspected');
  111. });
  112. }
  113.  
  114. //if CTRL key has pressed
  115. if(e.ctrlKey){
  116.  
  117. //prevent the default function of the cliked element
  118. e.preventDefault();
  119.  
  120. //clear console
  121. console.clear();
  122.  
  123. //if clicked element returned valid DOI
  124. if(findDOI(e.target)){
  125.  
  126. //add DOI attribute to the buttons
  127. $('input.DOI-unlock-button').attr('data-doi',findDOI(e.target));
  128.  
  129. //add highlight to the clicked element
  130. e.target.classList.add("DOI-unlock-inspected");
  131. }
  132. }
  133. });
  134.  
  135. //================================================== style the buttons
  136. GM_addStyle(`
  137. #scihub{
  138. left:0 !important;
  139. }
  140. #zlib{
  141. left:100px !important;
  142. }
  143. #libgen{
  144. left:200px !important;
  145. }
  146. .DOI-unlock-button{
  147. z-index:99999999;
  148. width:100px !important;
  149. height:30px !important;
  150. background:black !important;
  151. color:white !important;
  152. cursor:pointer;
  153. display:none !important;
  154. position:fixed !important;
  155. bottom:0 !important;
  156. border:none !important;
  157. box-shadow:0 0 0 1px white inset;
  158. margin:0 !important;
  159. padding:0 !important;
  160. font-size:inherit !important;
  161. text-align:center !important;
  162. }
  163. .DOI-unlock-inspected{
  164. background:yellow !important;
  165. color:black !important;
  166. font-size:130% !important;
  167. padding:5px !important;
  168. }
  169. *[data-doi]{
  170. display:block !important;
  171. }
  172. `);
  173. });