// ==UserScript== // @name DMZJ漫画转为手机版链接 // @author Crab // @namespace DMZJManga@dmzj.com // @description DMZJ漫画更新页面链接转为手机版 // @include http://i.178.com/~sms.cartoon.cartoonListUid* // @include http://i.178.com/~sms.cartoon.cartoonNewList* // @include http://m.dmzj.com/* // @include http://manhua.dmzj.com/* // @include http://user.dmzj.com/my/subscribe/mh/* // @include http://i.dmzj.com/subscribe* // @version 0.3 // @grant none // @downloadURL none // ==/UserScript== (function(){ if(location.hostname.indexOf('m.dmzj.com') > -1 && top !== self){ return (function(){ addEventListener('message', function(event){ if(event.data.nid !== 'dmzj_get_chapters') return; var req = new XMLHttpRequest(); req.open('GET', event.data.url, true); req.onload = function () { event.data.response = this.responseText; top.postMessage(event.data, event.origin); }; req.send(); }); top.postMessage({nid: 'dmzj_get_chapters'}, '*'); })(); }; var gUrl = (function(){ var url = document.URL; if(/cartoonListUid|cartoonNewList/g.test(url)){ return 'cartoonList'; }else if(/^http:\/\/manhua\.dmzj\.com\/update\_\d+\.shtml$/.test(url)){ return 'update'; }else if(/^http:\/\/m\.dmzj\.com\/view\/.+\.html(\?t=\d+#\d+)?$/.test(url)){ return 'mobile'; }else if(/^http:\/\/m\.dmzj\.com\/([^\/\.]+\.html)?(\?t=\d+#\d+)?$/.test(url)){ return 'mobileHome'; }else if(/^http:\/\/manhua\.dmzj\.com\/.+$/.test(url)){ return 'desktop'; }else if(/^http:\/\/user\.dmzj\.com\/.+$/.test(url)){ return 'oldSubscribe'; }else if(/^http:\/\/i\.dmzj\.com\/subscribe.*$/.test(url)){ return 'subscribe'; } })(); var $$ = function(e){ return Array.from(document.querySelectorAll(e)) }; //console.log(gUrl); var toMobileLink = function(a){ var a1 = a.cloneNode(true); a1.textContent = '(#)'; a1.style.color = 'orange'; a.parentNode.insertBefore(a1, a.nextSibling); a.href = a.href.replace(/\/\/manhua([^\/]+)/,'//m$1/view').replace(/shtml$/, 'html'); }; window._cE = function (name, attr, parent){ var e = document.createElement(name); for (var i in attr || []) i == 'text' ? (e.textContent = attr[i]) : e.setAttribute(i, attr[i]); parent && (Array.isArray(parent) ? parent[0].insertBefore(e, parent.length == 2 ? parent[1] : parent[0].firstChild) : parent.appendChild(e)); return e; }; if(gUrl == 'cartoonList'){ $$('.acg-content-text a[href$=shtml]').forEach(toMobileLink); }if(gUrl == 'update'){ $$('.pictext a[href$=shtml]').forEach(toMobileLink); //漫画更新页面国漫灰色显示 $$('.pictext a[href^="http\:\/\/www\.dmzj\.com\/"]').forEach(function(a){ var boxdiv = a; while(boxdiv){ if(boxdiv.className == 'boxdiv1') return boxdiv.classList.add('filter'); boxdiv = boxdiv.parentNode; } }); _cE('style', {text: '.boxdiv1.filter:not(:hover){ filter: grayscale(100%);}'}, document.head); }else if(gUrl == 'desktop'){ $$('.cartoon_online_border a[title][href$=shtml]').forEach(toMobileLink); //被隐藏的漫画至少显示最新话 var mhContainer = $$('.cartoon_online_border')[0]; if(mhContainer.firstElementChild.localName == 'img'){ mhContainer.innerHTML = ''+ g_last_update +'(#)' +'

正在加载被屏蔽的地址...

'; var iframe = _cE('iframe', {style: 'display:none', src: 'http://m.dmzj.com/xhr'}, document.body); addEventListener('message', function(e){ if(!e.data.nid == 'dmzj_get_chapters') return; if(!e.data.response) return e.source.postMessage({nid: e.data.nid, url: '/info/'+ g_comic_id + '.html'}, e.origin); mhContainer.innerHTML = ''; JSON.parse(e.data.response.match(/