closeDoublePage

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

当前为 2019-06-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name closeDoublePage
  3. // @version 0.4
  4. // @description Closes the old tab, if a new one with the same URL emerges.
  5. // @author CennoxX
  6. // @contact cesar.bernard@gmx.de
  7. // @homepage https://twitter.com/CennoxX
  8. // @namespace https://greasyfork.org/users/21515
  9. // @include *
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant window.close
  13. // @license MIT
  14. // ==/UserScript==
  15. sessionStorage.setItem('firstTimeOpened',new Date());
  16. //unsafeWindow.cdp_firstTimeOpened=new Date();
  17. GM_setValue('log', document.URL + '##' + sessionStorage.getItem('firstTimeOpened'));
  18. var oldLogs = '';
  19. setInterval(function() {
  20. var logs = GM_getValue('log');
  21. if (oldLogs != logs) {
  22. if (document.URL==logs.split('##')[0] && sessionStorage.getItem('firstTimeOpened') != logs.split('##')[1])
  23. {
  24. window.close()
  25. }
  26. else
  27. {
  28. oldLogs = logs;
  29. }
  30. }
  31. }, 500);