// ==UserScript== // @name zherop小工具 // @namespace http://tampermonkey.net/ // @version 0.3 // @description 一键无图、隐藏图片、查看源代码 // @author zherop@163.com // @match *://*/* // @connect static.61read.com // @require https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant GM_download // @grant GM_openInTab // @license AGPL License // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 定义 var menus = [ {"code":"noPic","name":"一键无图","event":"noPic"}, {"code":"hidePic","name":"隐藏图片","event":"hidePic"}, {"code":"viewSource","name":"查看源代码","event":"viewSource"}, {"code":"downloadPng","name":"下载图片","event":"downloadPng"}, {"code":"openIframe","name":"访问iframe","event":"openIframe"} ] // 菜单样式 function menuStyle() { return ` ` } // 创建菜单DOM function createMenuDom() { var html = '
' menus.forEach(item => { html += `
${item.name}
` }) html += '
' return html; } // 菜单事件 // 一键无图 function noPic(){ $("img").remove(); $("svg").remove(); } // 隐藏图片 function hidePic(){ $("img").hide(); $("svg").hide(); } // 查看源代码 function viewSource() { GM_openInTab('view-source:' + window.location.href) } // 下载图片 function downloadPng() { var currentHref = window.location.href if(currentHref.startsWith('http://static.61read.com/')) { var baseURL = currentHref.substr(0,currentHref.lastIndexOf('/')) var xmlFile = unsafeWindow.xmlFile var pageFile = unsafeWindow.pageFile GM_xmlhttpRequest({ method: "GET", url: baseURL + '/'+ pageFile + xmlFile, headers: { "Content-Type": "application/xml" }, onload: function(response) { var responseXML = response.responseXML var items = responseXML.getElementsByTagName('item') for(var i=0;i 0) { name = path.substring(path.lastIndexOf('/') + 1) } download(imageURL,name); } } }); } else { } } function download(filePath,name){ fetch(filePath).then(res => res.blob()).then(blob => { const a = document.createElement('a'); document.body.appendChild(a) a.style.display = 'none' // 使用获取到的blob对象创建的url const url = window.URL.createObjectURL(blob); a.href = url; // 指定下载的文件名 a.download = name; a.click(); document.body.removeChild(a) // 移除blob对象的url window.URL.revokeObjectURL(url); }); } function download2(url,name) { GM_download({ url: url, onerror: function (error) { console.log(error) }, onprogress: (pro) => { console.log(pro.loaded) //文件加载量 console.log(pro.totalSize) //文件总大小 }, ontimeout: () => { //如果此下载由于超时而失败,则要执行的回调 }, onload: () => { //如果此下载完成,则要执行的回调 } }) } // 打开iframe function openIframe() { if(document.getElementsByTagName("iframe").length > 0){ window.open(document.getElementsByTagName("iframe")[0].src) } else { console.log('不存在iframe') } } function copyText(text) { if($('#zp-copy').length <= 0) { $("body").append('') } $('#zp-copy').text(text).show(); var ele = document.getElementById("zp-copy"); ele.select(); document.execCommand('copy', false, null); $('#zp-copy').hide(); alert('复制链接成功!'); } $(function(){ $("head").append(menuStyle()) $("body").append(createMenuDom()) if(document.getElementsByTagName("iframe").length == 0){ $(".zp-menu-item[type='openIframe']").hide() } // 菜单绑定事件 $("#zp-menu .zp-menu-item").click(function(){ var opType = $(this).attr("type") var currentMenu = menus.find(item => item.code===opType) if(currentMenu) { eval(currentMenu.event + "()") } }) }) })();