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
| <script type="text/javascript"> function hasClass(obj, cls) { return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); } function addClass(obj, cls) { if (!this.hasClass(obj, cls)) obj.className += " " + cls; } function removeClass(obj, cls) { if (hasClass(obj, cls)) { var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)'); obj.className = obj.className.replace(reg, ' '); } }
function copyToClip(event) { let cb = event.target.parentNode var cls = cb.getElementsByClassName("line");
var pt = "" for (var k = 0; k < cls.length; k++) { var cl = (cls[k].textContent || cls[k].innerHTML); cl = cl.replace(`<span class="css"></span>`, "\n") cl = cl.replace(`<span class="javascript"></span>`, "\n")
pt += cl pt += "\n"; } const textarea = document.createElement('textarea'); textarea.value = pt; document.body.appendChild(textarea); textarea.select(); if (document.execCommand('copy')) { document.execCommand('copy'); } document.body.removeChild(textarea); alert("复制成功"); }
function doAddCopyCode() { var codeBlocks = document.getElementsByClassName('code'); for (var i = 0; i < codeBlocks.length; i++) { var divCopy = document.createElement("div"); divCopy.innerHTML = "点击复制" var divattr = document.createAttribute("class"); divattr.value = "copy_my_code";
divCopy.setAttributeNode(divattr); codeBlocks[i].appendChild(divCopy)
var code = codeBlocks[i].getElementsByTagName("pre")[1];
codeBlocks[i].onclick = (e) => { copyToClip(e);
} } }
function doAddImg() { var imgAll = document.getElementsByClassName('post-body')[0]; if (imgAll == undefined) { return; }
var imgs = imgAll.getElementsByTagName('img') for (var i = 0; i < imgs.length; i++) { if (hasClass(imgs[i], 'class_no_full_screen')) { continue; }
imgs[i].setAttribute('style', "cursor: zoom-in"); imgs[i].onclick = function () {
var section = document.getElementsByTagName("section")[0];
var imgView = document.getElementById('imgViewDom'); if (imgView == undefined) { imgView = document.createElement("div"); imgView.id = "imgViewDom";
section.appendChild(imgView)
imgView.onclick = function () { addClass(imgView, "disnone"); imgView.innerHTML = ""; }
}
imgView.innerHTML = "<img id = 'jackslowfuck' src=" + this.src + " style='cursor: zoom-out; max-width: 100%;'" + ">"; removeClass(imgView, "disnone");
var jackslowfuck = document.getElementById('jackslowfuck'); jackslowfuck.onclick = function () { addClass(imgView, "disnone"); imgView.innerHTML = ""; }
} } } window.addEventListener('load', function () { doAddImg(); doAddCopyCode(); }, false); </scirpt>
|