NGA上传无水印、不压缩

自动设置NGA附件上传选项为无水印、不压缩

// ==UserScript==
// @name         NGA上传无水印、不压缩
// @namespace    wordpure
// @version      0.3
// @description  自动设置NGA附件上传选项为无水印、不压缩
// @author       wordpure
// @match        *://nga.178.com/post.php*
// @match        *://bbs.nga.cn/post.php*
// @match        *://ngabbs.com/post.php*
// @icon         data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OTIiIGhlaWdodD0iNDkyIj4KICA8cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjRkVGOUUzIiByeD0iMjAlIiByeT0iMjAlIi8+CiAgPHBhdGggZmlsbD0iI2Y3Y2U5OCIgZD0ibTE5NCA5NyA0NC03N2gxbC0yIDg5LTQzLTEyWm0xMDEgMzMtNDAtMTF2LTFsNDktOTFoMWwtOSAxMDNoLTFabS0xMTgtMTUtMjkgMjItMzYtMTJ2LTFsMzYtNjhoMWw3IDQxIDIxIDE4Wm0xNzggMzctMSAxLTQwLTEyYTEgMSAwIDAgMS0xLTFsNTAtODNxMS0yIDAgMGwtOCA5NVptNTgtNDQtMiA2N3YxbC0zNi0xMSAzOC01N1ptLTI0MiA1NyA0OS00MGEyIDIgMzUgMCAxIDIgMGwxNDYgNDlxMiAwIDAgMGwtMjcxIDF2LTFsMjAtMjYgNTQgMTdaIi8+CiAgPHBhdGggZmlsbD0iIzk1NTM0MyIgZD0ibTE4NyAxOTQtNSAzNy0yIDEyLTMzIDl2LTZsOC01MmExIDEtODUgMCAxIDEgMGgzMVptLTY5IDggMSAyIDggMjMgMTEgMjgtMjggOC00LTlxMC0xIDAgMGwtMiAxMi0zNCAxMiAxMS03MHEwLTUgMi04IDQtNiAxMi02aDEybDYgMyA1IDVabTE5My04IDEgMjItNDcgOC0xIDEgMiAxaDMyLTYybC0xIDQtMzMgNyAxLTYgMi0xM3ExLTExIDktMThsMTAtNSAxMi0x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run-at       document-idle
// @supportURL   https://gf.qytechs.cn/zh-CN/scripts/516726/feedback
// @homepageURL  https://gf.qytechs.cn/zh-CN/scripts/516726
// ==/UserScript==

(function() {
  'use strict';

  const CONFIG = {
    // 6:默认无水印,1:默认右下水印,2:默认左下水印,3:默认左上水印,4:默认右上水印,5:默认中央水印
    watermarkIndex: 6,
    // 是否自动压缩
    isCompress: false
  };

  const SELECTORS = {
    uploadConfig: '#attachformC > a',
    watermarkConfig: '#attachformC select',
    compressConfig: '#attachformC select + [type="checkbox"]'
  };

  function showMessage(msg, type = 'warn') {
    console[type](`[NGA上传无水印、不压缩] ${msg}`);
  }

  function initializeUploadSettings() {
    const elements = {};

    for (const [key, selector] of Object.entries(SELECTORS)) {
      elements[key] = document.querySelector(selector);
      if (!elements[key]) {
        showMessage(`未找到元素 ${key}: (${selector})`);
        return null;
      }
    }

    return elements;
  }

  function applySettings(elements) {
    try {
      if (typeof postfunc === 'undefined') {
        showMessage('未找到对象 postfunc', 'error');
        return;
      }

      // 修改附件上传设置和对应的网页显示
      elements.uploadConfig.style.display = 'none';
      elements.uploadConfig.nextElementSibling.style.display = '';

      // 水印
      elements.watermarkConfig.selectedIndex = CONFIG.watermarkIndex;
      postfunc.wmdefsel = CONFIG.watermarkIndex - 1;

      // 压缩
      elements.compressConfig.checked = !CONFIG.isCompress;
      postfunc.defNoScale = !CONFIG.isCompress;

      // 上传附件自动应用设置
      postfunc.autoUploadSW(true);

      showMessage(`设置成功。\r\n当前设置:\r\n${JSON.stringify(CONFIG, null, 2)}`, 'info');
    } catch (error) {
      showMessage(`设置失败!\r\n${error.message}\r\n当前设置:\r\n${JSON.stringify(CONFIG, null, 2)}`, 'error');
    }
  }

  const elements = initializeUploadSettings();
  if (elements) {
    applySettings(elements);
  }

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址