ChatGPT Tab Keeper

To keep tabs not killed

  1. // ==UserScript==
  2. // @name ChatGPT Tab Keeper
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description To keep tabs not killed
  6. // @author CY Fung
  7. // @match https://chat.openai.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  9. // @grant none
  10. // @run-at document-idle
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16. // console.log(344);
  17.  
  18. if (window.name === 'chatgpt-tab-keeper' && window !== top && location.pathname.includes('robots.txt')) {
  19.  
  20.  
  21.  
  22. location.hash = '#' + Date.now();
  23. setTimeout(() => {
  24. // let db = document.dbForTabKeep;
  25. // if ('close' in db) db.close();
  26.  
  27. Promise.resolve(0).then(() => {
  28.  
  29.  
  30. location.reload(true);
  31. });
  32.  
  33. }, Math.floor(Math.random() * 5) * 1000 + 9000);
  34.  
  35.  
  36. /*
  37. setInterval(() => {
  38.  
  39. location.hash = '#'+Date.now();
  40.  
  41. }, 9000);
  42. */
  43.  
  44.  
  45. /*
  46.  
  47. // First, open a connection to a database
  48. const request = indexedDB.open('db_openai_tab_keep_db', 1);
  49.  
  50. document.dbForTabKeep = request
  51.  
  52. request.onsuccess = function (event) {
  53. const db = event.target.result;
  54. document.dbForTabKeep = db;
  55.  
  56. // Do something with the database...
  57.  
  58. // Close the request when you're done with the database
  59. db.close();
  60. };
  61. */
  62.  
  63.  
  64. } else if (window === top) {
  65.  
  66. let iframe = document.createElement('iframe');
  67. Object.assign(iframe.style, {
  68. transform: 'scale(0.0001) translate(-200vh, -200vh)',
  69. opacity: 0,
  70. pointerEvents: 'none',
  71. display: 'block',
  72. width: '64px',
  73. height: '64px',
  74. position: 'fixed',
  75. top: '0px',
  76. left: '0px'
  77. });
  78. iframe.name='chatgpt-tab-keeper';
  79. iframe.setAttribute('referrerpolicy','no-referrer');
  80. iframe.setAttribute('sandbox',"allow-scripts");
  81. document.body.appendChild(iframe);
  82. iframe.src = 'https://chat.openai.com/robots.txt';
  83.  
  84.  
  85.  
  86. // First, open a connection to a database
  87. const request = indexedDB.open('db_openai_tab_keep_db', 1);
  88.  
  89. document.dbForTabKeep = request
  90.  
  91.  
  92. }
  93.  
  94. // Your code here...
  95. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址