YuketangHelper.content.js

用于插件页面的构建

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/521021/1504836/YuketangHelpercontentjs.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// 插入一个触发按钮到页面
const triggerButton = document.createElement('button');
triggerButton.textContent = '查看作业';
triggerButton.style.position = 'fixed'; 
triggerButton.style.bottom = '40px';
triggerButton.style.right = '40px';
triggerButton.style.padding = '10px 20px';
triggerButton.style.fontSize = '16px';
triggerButton.style.cursor = 'pointer';
triggerButton.style.zIndex = '10000';
triggerButton.style.backgroundColor = '#007bff';
triggerButton.style.color = '#fff';
triggerButton.style.border = 'none';
triggerButton.style.borderRadius = '5px';
triggerButton.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.2)';
document.body.appendChild(triggerButton);

// 点击按钮时显示 iframe
triggerButton.addEventListener('click', () => {
  // 检查是否已经存在 iframe,避免重复添加
  if (document.getElementById('hwIframe'))
    return;

  // 创建 iframe 元素
  const iframe = document.createElement('iframe');
  
  iframe.id = 'hwIframe';
  iframe.src = chrome.runtime.getURL('hw.html'); // 插件内页面路径
  iframe.style.position = 'fixed';
  iframe.style.top = '10%';
  iframe.style.left = '10%';
  iframe.style.width = '80%';
  iframe.style.height = '80%';
  iframe.style.border = '2px solid #ccc';
  iframe.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.2)';
  iframe.style.zIndex = '10001';
  iframe.style.backgroundColor = '#fff';
  
  // 创建关闭按钮
  const closeBtn = document.createElement('button');
  closeBtn.textContent = '关闭';
  closeBtn.style.position = 'fixed';
  closeBtn.style.top = '10%';
  closeBtn.style.right = '10%';
  closeBtn.style.transform = 'translateX(-50%)';
  closeBtn.style.zIndex = '10002';
  closeBtn.style.padding = '5px 10px';
  closeBtn.style.cursor = 'pointer';
  closeBtn.style.backgroundColor = '#ff4d4f';
  closeBtn.style.color = '#fff';
  closeBtn.style.border = 'none';
  closeBtn.style.borderRadius = '5px';
  closeBtn.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.2)';
  
  // 点击关闭按钮时移除 iframe 和关闭按钮
  closeBtn.addEventListener('click', () => {
    iframe.remove();
    closeBtn.remove();
  });

    // 将 iframe 和关闭按钮插入页面
  document.body.appendChild(iframe);
  document.body.appendChild(closeBtn);
});