closeDoublePage

Closes the old tab, if a new one with the same URL emerges

  1. // ==UserScript==
  2. // @name closeDoublePage
  3. // @version 0.4.4
  4. // @description Closes the old tab, if a new one with the same URL emerges
  5. // @author CennoxX
  6. // @namespace https://greasyfork.org/users/21515
  7. // @homepage https://github.com/CennoxX/userscripts
  8. // @supportURL https://github.com/CennoxX/userscripts/issues/new?title=[closeDoublePage]%20
  9. // @match *://*/*
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant window.close
  13. // @license MIT
  14. // ==/UserScript==
  15. /* jshint esversion: 10 */
  16. /* eslint quotes: ["warn", "double", {"avoidEscape": true}] */
  17. /* eslint curly: "off" */
  18.  
  19. sessionStorage.setItem("firstTimeOpened",new Date());
  20. GM_setValue("log", document.URL + "##" + sessionStorage.getItem("firstTimeOpened"));
  21. var oldLogs = "";
  22. setInterval(function() {
  23. var logs = GM_getValue("log");
  24. if (oldLogs != logs) {
  25. if (document.URL==logs.split("##")[0] && sessionStorage.getItem("firstTimeOpened") != logs.split("##")[1])
  26. {
  27. window.close()
  28. }
  29. else
  30. {
  31. oldLogs = logs;
  32. }
  33. }
  34. }, 500);