Google scholar open in new tab

Middle click to open in new tab

  1. // ==UserScript==
  2. // @name Google scholar open in new tab
  3. // @namespace https://github.com/machsix
  4. // @match https://scholar.google.com/citations?*
  5. // @grant GM_openInTab
  6. // @grant GM.openInTab
  7. // @version 1.1
  8. // @author mach6
  9. // @license GPL-3.0
  10. // @description Middle click to open in new tab
  11. // ==/UserScript==
  12. (async()=>{
  13. const setRealHref = async () => {
  14. const elems = document.querySelectorAll('#gsc_a_tw a.gsc_a_at');
  15. await Promise.all([].map.call(elems, async(el) => {
  16. if (/^javascript/.test(el.href)) {
  17. const html = await (await fetch(`https://scholar.google.com/${el.getAttribute('data-href')}`)).text();
  18. const doc = new DOMParser().parseFromString(html, 'text/html');
  19. const realHref = doc.querySelector('a.gsc_vcd_title_link').href;
  20. el.setAttribute('href', realHref);
  21. }
  22. }));
  23. };
  24. await setRealHref();
  25. document.querySelector('#gsc_bpf_more').addEventListener('click', (e) => {
  26. setTimeout(() => {
  27. setRealHref().then(()=>{ e.preventDefault();});
  28. }, 1000);
  29. });
  30.  
  31. })();