[分享] 全屏模式 #385

thalient-aiAction Scripts 中发起了这个讨论。

[分享] 全屏模式 #385

thalient-ai thalient-ai 2024年9月10日 · 2 条评论

返回顶部

描述

这个脚本被触发后,将会隐藏/显示工具栏并将 Zotero 调整为全屏模式。默认 image 全屏 image

事件

操作

脚本

数据

/**
 * This script toggles Fullscreen mode for Zotero by hiding UI elements.
 * @author thalient-ai
 * @usage Assign to a hotkey
 * @link https://github.com/windingwind/zotero-actions-tags/discussions/
 * @see https://github.com/windingwind/zotero-actions-tags/discussions/
 */
(function () {
  const Zotero = require('Zotero');
  let mainWindow = Zotero.getMainWindow();
  const document = mainWindow.document;
  let isFullscreen = document.documentElement.classList.contains("fullscreen");
  let debounceTimeout = null;
  try {
    function mainScript() {
      // Set window chrome and tabs attributes
      document.documentElement.setAttribute('drawintitlebar', true);
      document.documentElement.setAttribute('tabsintitlebar', true);
      // Adjust chrome margin based on the OS
      if (Zotero.isMac) {
        document.documentElement.setAttribute('chromemargin', '0,-1,-1,-1');
      } else {
        document.documentElement.setAttribute('chromemargin', '0,2,2,2');
      }
      // Add fullscreen styles if not already added
      function addFullscreenStyles() {
        if (!document.querySelector("#fullscreen-style")) {
          const style = document.createElement("style");
          style.id = "fullscreen-style";
          style.textContent = `
            .fullscreen {
              margin: 0;
              padding: 0;
              overflow: hidden;
            }
            .fullscreen #mainPane {
              width: 100vw;
              height: 100vh;
            }
            .fullscreen .zotero-toolbar, 
            .fullscreen .zotero-tb-button,
            .fullscreen #zotero-title-bar,
            .fullscreen #main-menubar,
            .fullscreen #titlebar,  
            .fullscreen .topbar {
              display: none !important;
            }
          `;
          document.documentElement.appendChild(style);
        }
      }
      // Toggle fullscreen mode by showing or hiding elements
      function toggleFullscreenMode() {
        if (debounceTimeout) {
          clearTimeout(debounceTimeout);
        }
        debounceTimeout = setTimeout(() => {
          if (isFullscreen) {
            // Exiting fullscreen
            document.documentElement.classList.remove("fullscreen");
            isFullscreen = false;
          } else {
            // Entering fullscreen
            document.documentElement.classList.add("fullscreen");
            isFullscreen = true;
          }
        }, 300);
      }
      // Add styles and toggle fullscreen mode
      addFullscreenStyles();
      toggleFullscreenMode();
    }
    // Execute the script
    mainScript();
    
  } catch (error) {
    // Handle errors silently
  }
})();

补充说明

不保证在 MacOS 或 Linux 上能完美运行。 这适用于标签页 PDF 阅读器,而非窗口模式。


Beta 这个翻译有用吗? 提供反馈。

10 你必须登录才能投票

回复: 2 条评论

f-prettyland f-prettyland 2025年1月21日

在 Linux 上运行良好 (Action and Tags v2.1.0, Zotero v7.0.11)


Beta 这个翻译有用吗? 提供反馈。 1 你必须登录才能投票

wzzju wzzju 2025年3月31日

在 MacOS 上运行良好 (Action and Tags v2.1.0, Zotero v7.0.15)


Beta 这个翻译有用吗? 提供反馈。 1 你必须登录才能投票

免费注册 即可加入 GitHub 上的讨论。已有账号? 登录评论