Greasy Fork

Greasy Fork is available in English.

Overleaf - File History

Lets you use the browser history to navigate between previously opened files

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Overleaf - File History
// @namespace    https://github.com/BLumbye/overleaf-userscripts
// @version      0.1
// @description  Lets you use the browser history to navigate between previously opened files
// @author       Benjamin Lumbye
// @license      GPL-3
// @match        https://www.overleaf.com/project/*
// @grant        none
// ==/UserScript==

'use strict';

(function () {
  // Listen for file open events
  _ide.$scope.$on('doc:after-opened', onFileOpen);
  _ide.$scope.$on('file-view:file-opened', onFileOpen);

  // Listen for popstate event
  window.addEventListener('popstate', (event) => {
    if (event.state?.fileID) {
      openFile(event.state.fileID);
    }
  });
})();

function onFileOpen(event) {
  const fileID = _ide.fileTreeManager.selected_entity_id;
  if (history.state?.fileID === fileID) return;
  history.pushState({ fileID }, '');
}

function openFile(fileID) {
  const file = _ide.fileTreeManager.findEntityById(fileID);
  if (!file) return;
  if (file.type === 'file') {
    // BUG: File does not get highlighted in the file tree
    _ide.binaryFilesManager.openFile(file);
  } else if (file.type === 'doc') {
    _ide.editorManager.openDoc(file);
  }
}