1//22.12.8 updateï¼add mask 2//22.12.9 update: add search in this page 3function setMask(){//设置é®ç½©å± 4 if(document.getElementsByClassName("rmMask")[0]!=undefined){ 5 return document.getElementsByClassName("rmMask")[0]; 6 } 7 mask = document.createElement('div'); 8 mask.className = "rmMask"; 9 mask.style.width = window.innerWidth + 'px'; 10 mask.style.height = window.innerHeight + 'px'; 11 mask.style.background = '#fff'; 12 mask.style.opacity = '.0'; 13 mask.style.position = 'fixed'; 14 mask.style.top = '0'; 15 mask.style.left = '0'; 16 mask.style.zIndex = 998; 17 document.body.appendChild(mask); 18 document.getElementById("rightMenu").style.zIndex=19198; 19 return mask; 20} 21 22function insertAtCursor(myField, myValue) { 23 24 //IE æµè§å¨ 25 if (document.selection) { 26 myField.focus(); 27 sel = document.selection.createRange(); 28 sel.text = myValue; 29 sel.select(); 30 } 31 32 //FireFoxãChromeç 33 else if (myField.selectionStart || myField.selectionStart == '0') { 34 var startPos = myField.selectionStart; 35 var endPos = myField.selectionEnd; 36 37 // ä¿åæ»å¨æ¡ 38 var restoreTop = myField.scrollTop; 39 myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); 40 41 if (restoreTop > 0) { 42 myField.scrollTop = restoreTop; 43 } 44 45 myField.focus(); 46 myField.selectionStart = startPos + myValue.length; 47 myField.selectionEnd = startPos + myValue.length; 48 } else { 49 myField.value += myValue; 50 myField.focus(); 51 } 52} 53let rmf = {}; 54rmf.showRightMenu = function (isTrue, x = 0, y = 0) { 55 let $rightMenu = $('#rightMenu'); 56 $rightMenu.css('top', x + 'px').css('left', y + 'px'); 57 58 if (isTrue) { 59 $rightMenu.show(); 60 } else { 61 $rightMenu.hide(); 62 } 63} 64rmf.switchDarkMode = function () { 65 const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light' 66 if (nowMode === 'light') { 67 activateDarkMode() 68 saveToLocal.set('theme', 'dark', 2) 69 GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night) 70 } else { 71 activateLightMode() 72 saveToLocal.set('theme', 'light', 2) 73 GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day) 74 } 75 // handle some cases 76 typeof utterancesTheme === 'function' && utterancesTheme() 77 typeof FB === 'object' && window.loadFBComment() 78 window.DISQUS && document.getElementById('disqus_thread').children.length && setTimeout(() => window.disqusReset(), 200) 79}; 80rmf.yinyong=function(){ 81 var e = document.getElementsByClassName("el-textarea__inner")[0], 82 t = document.createEvent("HTMLEvents"); 83 t.initEvent("input", !0, !0), e.value = d.value = "> "+getSelection().toString()+"\n\n", e.dispatchEvent(t); 84 console.log(getSelection().toString()); 85 document.getElementsByClassName("el-textarea__inner")[0].value="> "+getSelection().toString()+"\n\n"; 86 Snackbar.show({ 87 text: '为ä¿è¯æä½³è¯è®ºé 读ä½éªï¼å»ºè®®ä¸è¦å é¤ç©ºè¡', 88 pos: 'top-center', 89 showAction: false, 90 }) 91} 92rmf.copyWordsLink = function () { 93 let url = window.location.href 94 let txa = document.createElement("textarea"); 95 txa.value = url; 96 document.body.appendChild(txa) 97 txa.select(); 98 document.execCommand("Copy"); 99 document.body.removeChild(txa); 100 Snackbar.show({ 101 text: '龿¥å¤å¶æåï¼å¿«å»å享å§ï¼', 102 pos: 'top-right', 103 showAction: false 104 }); 105} 106rmf.switchReadMode = function () { 107 const $body = document.body 108 $body.classList.add('read-mode') 109 const newEle = document.createElement('button') 110 newEle.type = 'button' 111 newEle.className = 'fas fa-sign-out-alt exit-readmode' 112 $body.appendChild(newEle) 113 114 function clickFn() { 115 $body.classList.remove('read-mode') 116 newEle.remove() 117 newEle.removeEventListener('click', clickFn) 118 } 119 120 newEle.addEventListener('click', clickFn) 121} 122 123//å¤å¶é䏿å 124rmf.copySelect = function () { 125 document.execCommand('Copy', false, null); 126 //è¿éå¯ä»¥åç¹ä¸è¥¿æç¤ºä¸ä¸ å·²å¤å¶ 127} 128
129//åå°é¡¶é¨ 130rmf.scrollToTop = function () { 131 document.getElementsByClassName("menus_items")[1].setAttribute("style",""); 132 document.getElementById("name-container").setAttribute("style","display:none"); 133 btf.scrollToDest(0, 500); 134} 135rmf.translate = function () { 136 document.getElementById("translateLink").click(); 137} 138rmf.searchinThisPage=()=>{ 139 document.body.removeChild(mask); 140 document.getElementsByClassName("local-search-box--input")[0].value=window.getSelection().toString() 141 document.getElementsByClassName("search")[0].click() 142 var evt = document.createEvent("HTMLEvents");evt.initEvent("input", false, false);document.getElementsByClassName("local-search-box--input")[0].dispatchEvent(evt); 143} 144document.body.addEventListener('touchmove', function(e){ 145 146}, { passive: false }); 147function popupMenu() { 148 //window.oncontextmenu=function(){return false;} 149 window.oncontextmenu = function (event) { 150 if(event.ctrlKey||document.body.clientWidth<900) return true; 151 $('.rightMenu-group.hide').hide(); 152 if (document.getSelection().toString()) { 153 $('#menu-text').show(); 154 } 155 if (document.getElementById('post')) { 156 $('#menu-post').show(); 157 } else { 158 if (document.getElementById('page')) { 159 $('#menu-post').show(); 160 } 161 } 162 var el = window.document.body; 163 el = event.target; 164 var a=/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/ 165 if (a.test(window.getSelection().toString())&&el.tagName!="A"){ 166 $('#menu-too').show() 167 } 168 if (el.tagName == 'A') { 169 $('#menu-to').show() 170 rmf.open = function () { 171 if(el.href.indexOf("http://")==-1&&el.href.indexOf("https://")==-1||el.href.indexOf("yisous.xyz")!=-1){ 172 pjax.loadUrl(el.href) 173 } 174 else{ 175 location.href = el.href 176 } 177 } 178 rmf.openWithNewTab = function () { 179 window.open(el.href); 180 // window.location.reload(); 181 } 182 rmf.copyLink = function () { 183 let url = el.href 184 let txa = document.createElement("textarea"); 185 txa.value = url; 186 document.body.appendChild(txa) 187 txa.select(); 188 document.execCommand("Copy"); 189 document.body.removeChild(txa); 190 } 191 } 192 if (el.tagName == 'IMG') { 193 $('#menu-img').show() 194 rmf.openWithNewTab = function () { 195 window.open(el.src); 196 // window.location.reload(); 197 } 198 rmf.click = function () { 199 el.click() 200 } 201 rmf.copyLink = function () { 202 let url = el.src 203 let txa = document.createElement("textarea"); 204 txa.value = url; 205 document.body.appendChild(txa) 206 txa.select(); 207 document.execCommand("Copy"); 208 document.body.removeChild(txa); 209 } 210 rmf.saveAs=function(){ 211 var a = document.createElement('a'); 212 var url = el.src; 213 var filename = url.split("/")[-1]; 214 a.href = url; 215 a.download = filename; 216 a.click(); 217 window.URL.revokeObjectURL(url); 218 } 219 } else if (el.tagName == "TEXTAREA" || el.tagName == "INPUT") { 220 $('#menu-paste').show(); 221 // rmf.paste=function(){ 222 // input.addEventListener('paste', async event => { 223 // event.preventDefault(); 224 // const text = await navigator.clipboard.readText(); 225 // el.value+=text; 226 // }); 227 // } 228 rmf.paste = function () { 229 navigator.permissions 230 .query({ 231 name: 'clipboard-read' 232 }) 233 .then(result => { 234 if (result.state == 'granted' || result.state == 'prompt') { 235 //读ååªè´´æ¿ 236 navigator.clipboard.readText().then(text => { 237 console.log(text) 238 insertAtCursor(el, text) 239 }) 240 } else { 241 Snackbar.show({ 242 text: '请å 许读ååªè´´æ¿ï¼', 243 pos: 'top-center', 244 showAction: false, 245 }) 246 } 247 }) 248 } 249 } 250 let pageX = event.clientX + 10; 251 let pageY = event.clientY; 252 let rmWidth = $('#rightMenu').width(); 253 let rmHeight = $('#rightMenu').height(); 254 if (pageX + rmWidth > window.innerWidth) { 255 pageX -= rmWidth + 10; 256 } 257 if (pageY + rmHeight > window.innerHeight) { 258 pageY -= pageY + rmHeight - window.innerHeight; 259 } 260 mask=setMask(); 261 window.onscroll=()=>{ 262 rmf.showRightMenu(false); 263 window.onscroll=()=>{} 264 document.body.removeChild(mask); 265 } 266 $(".rightMenu-item").click(()=>{ 267 document.body.removeChild(mask); 268 }) 269 $(window).resize(()=>{ 270 rmf.showRightMenu(false); 271 document.body.removeChild(mask); 272 }) 273 mask.onclick=()=>{ 274 document.body.removeChild(mask); 275 } 276 rmf.showRightMenu(true, pageY, pageX); 277 return false;
278 }; 279 280 window.addEventListener('click', function () { 281 rmf.showRightMenu(false); 282 }); 283} 284if (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { 285 popupMenu() 286} 287const box = document.documentElement 288 289function addLongtabListener(target, callback) { 290 let timer = 0 // åå§åtimer 291 292 target.ontouchstart = () => { 293 timer = 0 // éç½®timer 294 timer = setTimeout(() => { 295 callback(); 296 timer = 0 297 }, 380) // è¶ æ¶å¨è½æåæ§è¡ï¼è¯´ææ¯é¿æ 298 } 299 300 target.ontouchmove = () => { 301 clearTimeout(timer) // 妿æ¥å°è¿éï¼è¯´ææ¯æ»å¨ 302 timer = 0 303 } 304 305 target.ontouchend = () => { // å°è¿é妿timeræå¼ï¼è¯´ææ¤è§¦æ¸æ¶é´ä¸è¶³380msï¼æ¯ç¹å» 306 if (timer) { 307 clearTimeout(timer) 308 } 309 } 310} 311 312addLongtabListener(box, popupMenu)
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.