function showDivShare() { updateShareLinks(); document.getElementById("DIVSHARE").style.display="block"; return false; } function updateShareLinks() { var shortlink = "http://archive.ph/fZVQK"; var re = new RegExp(shortlink.replace(".", "\.") + "(#selection-[0-9.-]+)?"); var adr = document.location.hash.match(/(selection-\d+\.\d+-\d+\.\d+)/); document.getElementById("SHARE_SHORTLINK").value = document.getElementById("SHARE_SHORTLINK").value.replace(re, adr ? shortlink + document.location.hash : shortlink); document.getElementById("SHARE_MARKDOWN" ).value = document.getElementById("SHARE_MARKDOWN" ).value.replace(re, adr ? shortlink + document.location.hash : shortlink); document.getElementById("SHARE_HTMLCODE" ).value = document.getElementById("SHARE_HTMLCODE" ).value.replace(re, adr ? shortlink + document.location.hash : shortlink); document.getElementById("SHARE_WIKICODE" ).value = document.getElementById("SHARE_WIKICODE" ).value.replace(re, adr ? shortlink + document.location.hash : shortlink); } function findXY(obj) { var cur = {x:0, y:0}; while (obj && obj.offsetParent) { cur.x += obj.offsetLeft; // todo: + webkit-transform cur.y += obj.offsetTop; // todo: + webkit-transform obj = obj.offsetParent; } return cur; } function findXY2(obj, textpos) { // it could reset selection if (obj.nodeType==3) { var parent = obj.parentNode; var text = document.createTextNode(obj.data.substr(0, textpos)); var artificial = document.createElement("SPAN"); artificial.appendChild(document.createTextNode(obj.data.substr(textpos))); parent.insertBefore(text, obj); parent.replaceChild(artificial, obj); var y = findXY(artificial); parent.removeChild(text); parent.replaceChild(obj, artificial); return y; } else { return findXY(obj); } } var prevhash = ""; function scrollToHash() { if (document.location.hash.replace(/^#/, "")==prevhash.replace(/^#/, "")) return; prevhash = document.location.hash; if (document.location.hash.match(/#[0-9.]+%/)) { var p = parseFloat(document.location.hash.substring(1)); if (0 < p && p < 100 /*&& p%5 != 0*/) { var content = document.getElementById("CONTENT") var y = findXY(content).y + (content.offsetHeight)*p/100; window.scrollTo(0, y-16); } } var adr = document.location.hash.match(/selection-(\d+)\.(\d+)-(\d+)\.(\d+)/); if (adr) { var pos=0,begin=null,end=null; function recur(e) { if (e.nodeType==1 && (e.tagName=='OLD-META' || e.tagName=='OLD-SCRIPT')) return; if (e.nodeType==1) pos = (pos&~1)+2; if (e.nodeType==3) pos = pos|1; //if (e.nodeType==1) { // e.setAttribute('pos', pos); //} //if (e.nodeType==3) { // if (!e.textContent.match(/^\[/)) // e.textContent = '[' + pos + '] ' + e.textContent; //} if (pos==adr[1]) begin=[e, adr[2]]; if (pos==adr[3]) end =[e, adr[4]]; var lastChild = null; for (var i=0; i0 && end[0]>0) { newhash = "selection-"+begin[0]+"."+begin[1]+"-"+end[0]+"."+end[1]; } } } else if (document.selection) { // IE } try { var oldhash = location.hash.replace(/^#/, ""); if (oldhash != newhash) { prevhash = newhash; /* avoid firing window.onhashchange and scrolling */ if (history.replaceState) { history.replaceState('', document.title, document.location.origin + document.location.pathname + (newhash.length>0 ? '#'+newhash : '')); } else { if (newhash.length>0) location.hash = newhash; } } } catch(e) { // console.log(`e=` + e); } };