// ==UserScript== // @name 替换网页中的内容 // @namespace http://tampermonkey.net/ // @version 0.2 // @description 替换网页中的文本内容 // @author linmii // @include * // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; initCss(); initModal(); initRImg(); initDialog(); window.onscroll = function () { document.querySelector("#lm-r-img").style.top = document.documentElement.scrollTop + 'px'; let dialogDiv = document.querySelector("#lm-dialog-div"); dialogDiv.style.left = (document.documentElement.clientWidth - dialogDiv.style.width.replace('px', '')) / 2 + document.documentElement.scrollLeft + "px"; let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; dialogDiv.style.top = (document.documentElement.clientHeight - dialogDiv.style.width.replace('px', '')) / 2 + scrollTop + "px"; } })(); function initCss() { let 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;' + '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: inherit;' + '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 initRImg() { let rImg = document.createElement("div"); rImg.id = "lm-r-img"; rImg.innerText = 'R'; let top = document.documentElement.scrollTop + 'px'; rImg.style.cssText = "z-index: 999999; position: absolute; top: " + top + "; left: 0; border-radius: 4px; background-color: #fff; width: 20px; height: 20px; text-align: center; opacity: 0.5; cursor: pointer;"; document.querySelector("body").prepend(rImg); rImgBindEvent(); } function initModal() { let 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-btn-close").click(); }; document.querySelector("body").appendChild(lmModal); } function initDialog() { let dialogDiv = document.createElement("div"); dialogDiv.id = "lm-dialog-div"; let htmlText = '
'; htmlText += ''; htmlText += '