Greasy Fork

Greasy Fork is available in English.

文心一言去码工具

文心一言去除页面水印工具

目前为 2023-03-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         文心一言去码工具
// @namespace    http://tampermonkey.net/
// @version      0.3.3
// @description  文心一言去除页面水印工具
// @author       kj
// @match        https://yiyan.baidu.com/**
// @icon         https://www.google.com/s2/favicons?sz=64&domain=yiyan.baidu.com
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';
  const checkHit = dom => {
    return Array.from(dom.shadowRoot?.children || []).filter(e => /\w{5,16}/gi.exec(e.innerText)).filter(e => !!e.style.transform && !!e.style.zIndex).length > 10;
  }
  const hideIt = dom => {
    dom.style.visibility = 'hidden';
    dom.style.opacity = '0';
  }
  const observer = new MutationObserver((mutationsList, observer) => {
    mutationsList.forEach((mutation) => {
      if (mutation.addedNodes && mutation.addedNodes[0]) {
        if (checkHit(mutation.addedNodes[0])) {
          hideIt(mutation.addedNodes[0]);
        } else if (!!mutation.addedNodes[0].querySelector('.ant-modal-mask')) {
          hideIt(mutation.addedNodes[0]);
        }
      }
    });
  });
  observer.observe(document.body, {
    childList: true,
    attributes: true,
  });
  const doms = Array.from(document.querySelectorAll('div')).filter(e => checkHit(e));
  if (doms.length > 0) {
    doms[0].style.visibility = 'hidden';
    doms[0].style.opacity = '0';
  }
  const checkImage = (url, minWidth, minHeight) => {
    return new Promise((resolve, reject) => {
      const img = document.createElement('img');
      img.onload = function () {
        if (this.width >= minWidth && this.height >= minHeight) {
          resolve(true);
        } else {
          resolve(false);
        }
      }
      img.onerror = function () {
        reject(false);
      }
      img.src = url;
    });
  }
  setInterval(() => {
    Array.from(document.querySelectorAll('.custom-html img')).filter(e => /x-bce-process=style\/wm_ai/gi.exec(e.src)).forEach(e => {
      let url = e.src.replace(/x-bce-process=style\/wm_ai/gi, '');
      checkImage(url, 250, 250)
        .then(result => {
          if (result) {
            e.src = e.src.replace(/x-bce-process=style\/wm_ai/gi, '');
          }
        })
        .catch(error => {
          // console.error(error);
        });
    })
  }, 40);


})();