Skip to content

Commit

Permalink
6.4.8 恢复:设置界面的分离,新增下一页链接新标签页打开功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ywzhaiqi committed Nov 17, 2014
1 parent d8ab50e commit df7e7aa
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 282 deletions.
4 changes: 2 additions & 2 deletions Super_preloaderPlus/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(grunt) {
concat: {
dist: {
options: concatOptions,
src: ['src/meta.js', 'src/rule.js', 'src/main.js'],
src: ['src/meta.js', 'src/rule.js', 'src/setting.js', 'src/main.js'],
dest: '<%= pkg.name %>.user.js'
},
},
Expand Down Expand Up @@ -61,4 +61,4 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-watch')

}
}
150 changes: 11 additions & 139 deletions Super_preloaderPlus/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,145 +76,6 @@ var SP = {
},
};

var setup = function(){
var d = document;
var on = function(node, e, f) {
node.addEventListener(e, f, false);
};

var $ = function(s) { return d.getElementById('sp-prefs-'+s); };
if($('setup')) return;

var styleNode = GM_addStyle('\
#sp-prefs-setup { position:fixed;z-index:2147483647;top:30px;right:60px;padding:20px 30px;background:#eee;width:500px;border:1px solid black; }\
#sp-prefs-setup * { color:black;text-align:left;line-height:normal;font-size:12px; }\
#sp-prefs-setup a { color:black;text-decoration:underline; }\
#sp-prefs-setup div { text-align:center;font-weight:bold;font-size:14px; }\
#sp-prefs-setup ul { margin:15px 0 15px 0;padding:0;list-style:none;background:#eee;border:0; }\
#sp-prefs-setup input, #sp-prefs-setup select { border:1px solid gray;padding:2px;background:white; }\
#sp-prefs-setup li { margin:0;padding:6px 0;vertical-align:middle;background:#eee;border:0 }\
#sp-prefs-setup button { width:150px;margin:0 10px;text-align:center; }\
#sp-prefs-setup textarea { width:98%; height:60px; margin:3px 0; }\
#sp-prefs-setup b { font-weight: bold; font-family: "微软雅黑", sans-serif; }\
');

var div = d.createElement('div');
div.id = 'sp-prefs-setup';
d.body.appendChild(div);
div.innerHTML = '\
<div>Super_preloaderPlus_one 设置</div>\
<ul>\
<li>当前版本为 <b>' + scriptInfo.version + ' </b>,上次更新时间为 <b>'+ scriptInfo.updateTime
+ '</b><button id="sp-prefs-checkUpdate" style="width:auto;">更新</button>\
<a id="sp-prefs-homepageURL" target="_blank" href="' + scriptInfo.homepageURL + '"/>脚本主页</a>\
</li>\
<li><input type="checkbox" id="sp-prefs-debug" /> 调试模式</li>\
<li><input type="checkbox" id="sp-prefs-dblclick_pause" /> 鼠标双击暂停翻页(默认为 Ctrl + 长按左键)</li>\
<li><input type="checkbox" id="sp-prefs-enableHistory" /> 添加下一页到历史记录</li>\
<li><input type="checkbox" id="sp-prefs-SITEINFO_D-useiframe" /> 在预读模式下,默认启用 iframe 方式</li>\
<li><input type="checkbox" id="sp-prefs-SITEINFO_D-a_enable" /> 默认启用自动翻页 </li>\
<li><input type="checkbox" id="sp-prefs-SITEINFO_D-a_force_enable" /> 自动翻页默认启用强制拼接</li>\
<li>自定义排除列表:\
<div><textarea id="sp-prefs-excludes" placeholder="自定义排除列表,支持通配符。\n例如:http://*.douban.com/*"></textarea></div>\
</li>\
<li>自定义站点规则:\
<div><textarea id="sp-prefs-custom_siteinfo" placeholder="自定义站点规则"></textarea></div>\
</li>\
</ul>\
<div><button id="sp-prefs-ok">确定</button><button id="sp-prefs-cancel">取消</button></div>';
div = null;

var close = function() {
if (styleNode) {
styleNode.parentNode.removeChild(styleNode);
}
var div = $('setup');
div.parentNode.removeChild(div);
};

on($('ok'), 'click', function(){
GM_setValue('enableHistory', prefs.enableHistory = !!$('enableHistory').checked);
GM_setValue('SITEINFO_D.useiframe', SITEINFO_D.useiframe = !!$('SITEINFO_D-useiframe').checked);
GM_setValue('SITEINFO_D.autopager.enable', SITEINFO_D.autopager.enable = !!$('SITEINFO_D-a_enable').checked);
GM_setValue('SITEINFO_D.autopager.force_enable', SITEINFO_D.autopager.force_enable = !!$('SITEINFO_D-a_force_enable').checked);

GM_setValue('debug', xbug = !!$('debug').checked);
debug = xbug ? console.log.bind(console) : function() {};

GM_setValue('dblclick_pause', $('dblclick_pause').checked);
GM_setValue('excludes', prefs.excludes = $('excludes').value);
GM_setValue('custom_siteinfo', prefs.custom_siteinfo = $('custom_siteinfo').value);

SP.loadSetting();

close();
});

on($('cancel'), 'click', close);

$('checkUpdate').onclick = checkUpdate;
$('debug').checked = xbug;
$('enableHistory').checked = prefs.enableHistory;
$('dblclick_pause').checked = GM_getValue('dblclick_pause') || false;
$('SITEINFO_D-useiframe').checked = SITEINFO_D.useiframe;
$('SITEINFO_D-a_enable').checked = SITEINFO_D.autopager.enable;
$('SITEINFO_D-a_force_enable').checked = SITEINFO_D.autopager.force_enable;
$('excludes').value = prefs.excludes;
$('custom_siteinfo').value = prefs.custom_siteinfo;

// 打开设置自动检查更新
checkUpdate();
};

var isUpdating = true;
function checkUpdate() {
if (isUpdating) {
return;
}

GM_xmlhttpRequest({
method: "GET",
url: scriptInfo.metaUrl,
onload: function(response) {
var txt = response.responseText;
var curVersion = scriptInfo.version;
var latestVersion = txt.match(/@\s*version\s*([\d\.]+)\s*/i);
if (latestVersion) {
latestVersion = latestVersion[1];
} else {
alert('解析版本号错误');
return;
}

//对比版本号
var needUpdate;
var latestVersion = latestVersion.split('.');
var lVLength = latestVersion.length;
var currentVersion = curVersion.split('.');
var cVLength = currentVersion.length;
var lV_x;
var cV_x;
for (var i = 0; i < lVLength; i++) {
lV_x = Number(latestVersion[i]);
cV_x = (i >= cVLength) ? 0 : Number(currentVersion[i]);
if (lV_x > cV_x) {
needUpdate = true;
break;
} else if (lV_x < cV_x) {
break;
}
}

if (needUpdate) {
alert('本脚本从版本 ' + scriptInfo.version + ' 更新到了版本 ' + latestVersion + '.\n请点击脚本主页进行安装');
document.getElementById("sp-prefs-homepageURL").boxShadow = '0 0 2px 2px #FF5555';
}

isUpdating = false;
}
});
}


function init(window, document) {
var startTime = new Date();
Expand Down Expand Up @@ -1332,6 +1193,17 @@ function init(window, document) {
imgs = getAllElements('css;img[src]', fragment); //收集所有图片
}

// 处理下一页内容部分链接是否新标签页打开
if (prefs.forceTargetWindow) {
var arr = Array.prototype.slice.call(fragment.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'));
arr.forEach(function (elem){
elem.setAttribute('target', '_blank');
if (elem.getAttribute('onclick') == 'atarget(this)') { // 卡饭论坛的控制是否在新标签页打开
elem.removeAttribute('onclick');
}
});
}

var sepdiv = createSep(lastUrl, cplink, nextlink);
if (pageElements[0] && pageElements[0].tagName == 'TR') {
var insertParent = insertPoint.parentNode;
Expand Down
59 changes: 32 additions & 27 deletions Super_preloaderPlus/src/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var prefs={
sepStartN: 2, // 翻页导航上的,从几开始计数.(貌似有人在意这个,所以弄个开关出来,反正简单.-_-!!)

// 新增或修改的
forceTargetWindow: GM_getValue('forceTargetWindow', true), // 下一页的链接设置成在新标签页打开
debug: GM_getValue('debug', false),
enableHistory: GM_getValue('enableHistory', false), // 把下一页链接添加到历史记录
autoGetPreLink: false, // 一开始不自动查找上一页链接,改为调用时再查找
Expand Down Expand Up @@ -171,6 +172,9 @@ var SITEINFO=[
if (elem.className != oClassName)
elem.className = oClassName;
});
},
filter: function() { // 在添加内容到页面后运行

},
startFilter: function(win, doc) { // 只作用一次
// 移除 Google 重定向
Expand Down Expand Up @@ -2827,33 +2831,34 @@ var SITEINFO=[
}
}
},
{name: 'SF在线漫画',
url:/http:\/\/comic\.sfacg\.com\/HTML\/.+/i,
siteExample:'http://comic.sfacg.com/HTML/HZDLQ/243/?p=2',
preLink:{
startAfter:'?p=',
inc:-1,
min:1,
},
nextLink:{
startAfter:'?p=',
mFails:[/http:\/\/comic\.sfacg\.com\/HTML\/.+\//i,'?p=1'],
inc:1,
isLast:function(doc,win,lhref){
var pageSel=doc.getElementById('pageSel');
if(pageSel){
var s2os=pageSel.options;
var s2osl=s2os.length;
if(pageSel.selectedIndex==s2osl-1)return true;
}
},
},
autopager:{
pageElement:'//img[@id="curPic"]',
useiframe:true,
replaceE: 'id("Pages")'
}
},
// 已失效
// {name: 'SF在线漫画',
// url:/http:\/\/comic\.sfacg\.com\/HTML\/.+/i,
// siteExample:'http://comic.sfacg.com/HTML/ZXCHZ/001/#p=2',
// preLink:{
// startAfter:'#p=',
// inc:-1,
// min:1,
// },
// nextLink:{
// startAfter:'#p=',
// mFails:[/http:\/\/comic\.sfacg\.com\/HTML\/.+\//i,'#p=1'],
// inc:1,
// isLast:function(doc,win,lhref){
// var pageSel=doc.getElementById('pageSel');
// if(pageSel){
// var s2os=pageSel.options;
// var s2osl=s2os.length;
// if(pageSel.selectedIndex==s2osl-1)return true;
// }
// },
// },
// autopager:{
// pageElement:'//img[@id="curPic"]',
// useiframe:true,
// replaceE: 'id("Pages")'
// }
// },
{name: '热血漫画',
url: /^http:\/\/www\.rexuedongman\.com\/comic\//i,
siteExample: 'http://www.rexuedongman.com/comic/2957/36463/index.html?p=2',
Expand Down
Loading

0 comments on commit df7e7aa

Please sign in to comment.