ChatGPT Tab Keeper

To keep tabs not killed

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ChatGPT Tab Keeper
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  To keep tabs not killed
// @author       CY Fung
// @match        https://chat.openai.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant        none
// @run-at       document-idle
// @license MIT
// ==/UserScript==

(function () {
  'use strict';
  // console.log(344);

  if (window.name === 'chatgpt-tab-keeper' && window !== top && location.pathname.includes('robots.txt')) {



    location.hash = '#' + Date.now();
    setTimeout(() => {
     // let db = document.dbForTabKeep;
     // if ('close' in db) db.close();

      Promise.resolve(0).then(() => {


        location.reload(true);
      });

    }, Math.floor(Math.random() * 5) * 1000 + 9000);


    /*
  setInterval(() => {

    location.hash = '#'+Date.now();

  }, 9000);
    */


/*

    // First, open a connection to a database
    const request = indexedDB.open('db_openai_tab_keep_db', 1);

    document.dbForTabKeep = request

    request.onsuccess = function (event) {
      const db = event.target.result;
      document.dbForTabKeep = db;

      // Do something with the database...

      // Close the request when you're done with the database
      db.close();
    };
*/


  } else if (window === top) {

    let iframe = document.createElement('iframe');
    Object.assign(iframe.style, {
      transform: 'scale(0.0001) translate(-200vh, -200vh)',
      opacity: 0,
      pointerEvents: 'none',
      display: 'block',
      width: '64px',
      height: '64px',
      position: 'fixed',
      top: '0px',
      left: '0px'
    });
      iframe.name='chatgpt-tab-keeper';
      iframe.setAttribute('referrerpolicy','no-referrer');
        iframe.setAttribute('sandbox',"allow-scripts");
    document.body.appendChild(iframe);
    iframe.src = 'https://chat.openai.com/robots.txt';



    // First, open a connection to a database
    const request = indexedDB.open('db_openai_tab_keep_db', 1);

    document.dbForTabKeep = request


  }

  // Your code here...
})();