// ==UserScript== // @name 替换网页中的内容 // @name:en Replace content in a webpage(Revision) // @name:zh-CN 替换网页中的内容 // @name:zh-TW 替換網頁中的內容 // @namespace http://tampermonkey.net/ // @version 2.0.1 // @description 替换网页中的文本内容 // @description:en Replace text content in a webpage(Revision) // @description:zh-CN 替换网页中的文本内容 // @description:zh-TW 替換網頁中的文本內容 // @author linmii // @editor zesion // @include * // @grant none // @downloadURL https://update.greasyfork.icu/scripts/377730/%E6%9B%BF%E6%8D%A2%E7%BD%91%E9%A1%B5%E4%B8%AD%E7%9A%84%E5%86%85%E5%AE%B9.user.js // @updateURL https://update.greasyfork.icu/scripts/377730/%E6%9B%BF%E6%8D%A2%E7%BD%91%E9%A1%B5%E4%B8%AD%E7%9A%84%E5%86%85%E5%AE%B9.meta.js // ==/UserScript== /** * TO DO List * 1.增加整页内容替换功能,个人感觉整页内容替换没什么意义 * * * 已知bug * 1. 存在iframe的页面无法进行替换 * * * V1.0.3 2019-08-05 更新内容 * 1. 解决模态框弹出页面无法输入的问题。 * 2. 增加是否替换禁用文本框内容的功能 * 3. 修改脚本只替换文本框内容的功能 * * V1.0.4 2019-12-31 更新内容 * 1. 解决一个页面出现多个替换图标的问题。 * 2. 解决在某些网页,弹窗飘到屏幕顶部无法输入的问题,如1688网站订单页面。 * * V1.1 2020-02-06 更新内容,bug修复 * 1. 解决弹窗在不同网页中高度不一致的问题 * 2. 解决脚本在阿里云后台,谷歌云后台等某些网站无法使用的问题。 * * V1.1.2 * 1. 清除数据后让查找输入框获得焦点 * * V2.0 * 本次进行了大版本更新,基本上是重写整个插件,采用了jquery框架,解决了纯js需要适配复杂页面等问题。 * * 新增功能: * 1. 重写插件,采用jquery框架,修复插件在一些页面出现的各种无法使用问题 * 2. 增加勾选,实现替换功能定制化 * 3. 增加打开弹窗自动定位到查找输入框,方便输入 * 功能优化: * 1. 优化弹出框高度的计算方法 * 2. 删除无用代码 * 3. 采用css方式对弹窗进行局中,去掉臃肿的js居中算法 * Bug修复: * 1. 修复某些页面弹窗显示问题,如淘宝产品详情页 * 2. 修复某些页面插件报onclick, onmouseover等奇怪问题,导致插件无法使用的问题 * 3. 增加勾选,实现替换功能定制化 * * V2.0.1 * 去掉jquery框架,继续采用原生javascrip编写插件,主要是发现jquery兼容问题比较差。 * 1. 修复原生JavaScript各种报错问题。 */ var elements = []; (function () { 'use strict'; initCss(); initModal(); initRImg(); initDialog(); removeTagAttibute('tabindex'); })(); /** * 初始化css样式 */ function initCss() { var lmStyle = document.createElement("style"); lmStyle.type = "text/css"; lmStyle.innerHTML = '.lm-r-button {' + 'padding: 10px 18px;' + 'font-size: 14px;' + 'border-radius: 4px;' + 'line-height: 1;' + 'white-space: nowrap;' + 'cursor: pointer;' + 'background: #409EFF;' // + 'border: 1px solid #409EFF;' + 'border: none;' + 'color: #fff;' + 'font-weight: 500;' + '}' + '.lm-r-button:hover {background: #66b1ff; border-color: #66b1ff; color: #fff;}' + '.lm-r-button:focus {background: #66b1ff; border-color: #66b1ff; color: #fff;}' + '.lm-r-input {' + '-webkit-appearance: none;' + 'background-color: #fff;' + 'background-image: none;' + 'border-radius: 4px;' + 'border: 1px solid #dcdfe6;' + 'box-sizing: border-box;' + 'color: #606266;' + 'display: inline-block;' + 'font-size: 14px;' + 'height: 40px;' + 'line-height: 40px;' + 'outline: none;' + 'padding: 0 15px;' + 'transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);' + 'width: 100%;' + '}' + '.lm-r-input:hover {border-color: #C0C4CC;}' + '.lm-r-input:focus {border-color: #409EFF;}'; document.querySelector("head").appendChild(lmStyle); } /** * 弹出框兼容 */ function removeTagAttibute(attributeName){ var allTags = '*'; var specificTags = ['DIV', 'ARTICLE', 'INPUT']; var allelems = document.querySelectorAll(specificTags); var i,j= 0; for(i = 0, j = 0; i < allelems.length; i++) { allelems[i].removeAttribute(attributeName); } } /** * 初始化R图标 */ function initRImg() { var rImg = document.createElement("div"); rImg.id = "lm-r-img"; rImg.innerText = 'R'; rImg.style.cssText = "z-index: 999999; position: fixed; top: 0; left: 0; font-size: 14px; border-radius: 4px; background-color: #fff; width: 20px; height: 20px; text-align: center; opacity: 0.5; cursor: pointer; border: solid 1px #999999;"; /*if (document.querySelector("body")){ document.querySelector("body").prepend(rImg); }*/ if(window.self === window.top){ if (document.querySelector("body")){ document.body.appendChild(rImg); } else { document.documentElement.appendChild(rImg); } } rImg.addEventListener('click',function () { document.querySelector("#lm-r-modal").style.display = 'block'; document.querySelector("#lm-dialog-div").style.display = 'block'; document.querySelector("#lm-find-content").focus(); }); rImg.addEventListener('mouseover', function () { document.querySelector("#lm-r-img").style.opacity = 1; }); rImg.addEventListener('mouseleave', function () { document.querySelector("#lm-r-img").style.opacity = 0.5; }); } /** * 初始化遮罩 */ function initModal() { var lmModal = document.createElement("div"); lmModal.id = 'lm-r-modal'; lmModal.style.cssText = 'position: fixed; left: 0; top: 0; width: 100%; height: 100%; opacity: 0.5; background: #000; z-index: 999999; display: none;'; lmModal.onclick = function () { document.querySelector("#lm-close-btn").click(); }; document.querySelector("body").appendChild(lmModal); } /** * 初始化弹出框 */ function initDialog() { var dialogDiv = document.createElement("div"); dialogDiv.id = "lm-dialog-div"; var htmlText = '