ChatGPT Tab Keeper

To keep tabs not killed

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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...
})();