1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
| console.log( "Codes uses GPL Licence" )
function insertAtCursor(myField, myValue) {
//IE 浏览器 if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; sel.select(); }
//FireFox、Chrome等 else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd;
// 保存滚动条 var restoreTop = myField.scrollTop; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
if (restoreTop > 0) { myField.scrollTop = restoreTop; }
myField.focus(); myField.selectionStart = startPos + myValue.length; myField.selectionEnd = startPos + myValue.length; } else { myField.value += myValue; myField.focus(); } } let rmf = {}; rmf.showRightMenu = function (isTrue, x = 0, y = 0) { let $rightMenu = $('#rightMenu'); $rightMenu.css('top', x + 'px').css('left', y + 'px');
if (isTrue) { $rightMenu.show(); } else { $rightMenu.hide(); } } rmf.switchDarkMode = function () { const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light' if (nowMode === 'light') { activateDarkMode() saveToLocal.set('theme', 'dark', 2) GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night) } else { activateLightMode() saveToLocal.set('theme', 'light', 2) GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day) } // handle some cases typeof utterancesTheme === 'function' && utterancesTheme() typeof FB === 'object' && window.loadFBComment() window.DISQUS && document.getElementById('disqus_thread').children.length && setTimeout(() => window.disqusReset(), 200) }; rmf.copyWordsLink = function () { let url = window.location.href let txa = document.createElement("textarea"); txa.value = url; document.body.appendChild(txa) txa.select(); document.execCommand("Copy"); document.body.removeChild(txa); swal({ icon: "success", text: "复制成功,如转载请注明出处!", button: false, timer: 1000, }); } rmf.switchReadMode = function () { const $body = document.body $body.classList.add('read-mode') const newEle = document.createElement('button') newEle.type = 'button' newEle.className = 'fas fa-sign-out-alt exit-readmode' $body.appendChild(newEle)
function clickFn() { $body.classList.remove('read-mode') newEle.remove() newEle.removeEventListener('click', clickFn) }
newEle.addEventListener('click', clickFn) }
//复制选中文字 rmf.copySelect = function () { document.execCommand('Copy', false, null); //这里可以写点东西提示一下 已复制 swal({ icon: "success", text: "复制成功,如转载请注明出处!", button: false, timer: 1000, }); }
//回到顶部 rmf.scrollToTop = function () { btf.scrollToDest(0, 500); } rmf.translate = function () { document.getElementById("translateLink").click(); }
// 右键菜单事件 document.onkeydown = function (event) { event = (event || window.event); if (event.keyCode == 17) { console.log("你知道的太多了"); return; } }
function popupMenu() { //window.oncontextmenu=function(){return false;} window.oncontextmenu = function (event) { // if(event.ctrlKey)return true; //ctrl右键原界面 console.log(event.keyCode) $('.rightMenu-group.hide').hide(); //如果有文字选中,则显示 文字选中相关的菜单项 if (document.getSelection().toString()) { $('#menu-text').show(); } if (document.getElementById('post')) { $('#menu-post').show(); } else { if (document.getElementById('page')) { $('#menu-post').show(); } } var el = window.document.body; el = event.target; var a=/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/ if (a.test(window.getSelection().toString())){ $('#menu-too').show() } if (el.tagName == 'A') { $('#menu-to').show() rmf.open = function () { location.href = el.href } rmf.openWithNewTab = function () { window.open(el.href); } rmf.copyLink = function () { let url = el.href let txa = document.createElement("textarea"); txa.value = url; document.body.appendChild(txa) txa.select(); document.execCommand("Copy"); document.body.removeChild(txa); } } if (el.tagName == 'IMG') { $('#menu-img').show() rmf.openWithNewTab = function () { window.open(el.src); } rmf.click = function () { el.click() } rmf.copyLink = function () { let url = el.src let txa = document.createElement("textarea"); txa.value = url; document.body.appendChild(txa) txa.select(); document.execCommand("Copy"); document.body.removeChild(txa); } } else if (el.tagName == "TEXTAREA" || el.tagName == "INPUT") { $('#menu-paste').show(); rmf.paste = function () { navigator.permissions .query({ name: 'clipboard-read' }) .then(result => { if (result.state == 'granted' || result.state == 'prompt') { //读取剪贴板 navigator.clipboard.readText().then(text => { console.log(text) insertAtCursor(el, text) }) } else { swal({ icon: "info", text: "请允许读取剪贴板!!", button: false, timer: 1000, }) } }) } } let pageX = event.clientX + 10; let pageY = event.clientY; let rmWidth = $('#rightMenu').width(); let rmHeight = $('#rightMenu').height(); if (pageX + rmWidth > window.innerWidth) { pageX -= rmWidth + 10; } if (pageY + rmHeight > window.innerHeight) { pageY -= pageY + rmHeight - window.innerHeight; }
rmf.showRightMenu(true, pageY, pageX); return false; };
window.addEventListener('click', function () { rmf.showRightMenu(false); }); } if (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { popupMenu() } const box = document.documentElement
function addLongtabListener(target, callback) { let timer = 0 // 初始化timer
target.ontouchstart = () => { timer = 0 // 重置timer timer = setTimeout(() => { callback(); timer = 0 }, 380) // 超时器能成功执行,说明是长按 }
target.ontouchmove = () => { clearTimeout(timer) // 如果来到这里,说明是滑动 timer = 0 }
target.ontouchend = () => { // 到这里如果timer有值,说明此触摸时间不足380ms,是点击 if (timer) { clearTimeout(timer) } } }
addLongtabListener(box, popupMenu)
//F12弹窗提示 document.onkeydown = function () { if (window.event && window.event.keyCode == 123) { event.keyCode = 0; event.returnValue = true; //可选是否开启F12功能 swal({ icon: "success", text: "开发者模式已打开,请遵守GPL协议", button: false, timer: 1000, }); } }
|