// ==UserScript==
// @name 福利吧论坛好孩子看得见
// @namespace https://greasyfork.org/zh-CN/users/193133-pana
// @homepage https://www.sailboatweb.com
// @version 6.4.5
// @description 好孩子才看得见,支持移动端
// @author pana
// @include http*://www.wnflb19.com/*
// @include http*://www.wnflb66.com/*
// @exclude http*://*/member.php?mod=register
// @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @grant GM_setClipboard
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @note 社会主义核心价值观编码: https://github.com/sym233/core-values-encoder
// @note ver.6.4.0 2019.9.23 修复论坛不显示base64编码图片的问题
// @note ver.6.3.0 2019.9.18 添加识别并提取文字中的链接设置
// @note ver.6.2.0 2019-9-11 添加浮动模式设置
// @note ver.5.0.0 2019-8-29 添加热帖高亮的功能 by theliang
// ==/UserScript==
(function() {
'use strict';
const SETTING_VALUE = {
WRAP_DIV: ['settingWrapDiv', ''],
MAIN_FIELDSET: ['mainFieldset', ''],
HEADLINE_LEGEND: ['headlineLegend', '好孩子看得见设置 v6.4.5'],
TAG_UL: ['tagUl', ''],
HIGHLIGHT_CHECKBOX: ['highlightCheckbox', '启用热帖高亮功能'],
AGREE_NUMBER_TEXT: ['agreeNumberText', '--> 分享高亮的阈值: '],
AGREE_NUMBER_INPUT: ['agreeNumberInput', '(推荐: 20)'],
AGREE_COLOR_TEXT: ['agreeColorText', '--> 分享高亮的颜色: '],
AGREE_COLOR_INPUT: ['agreeColorInput', '(推荐: #EE1B2E)'],
AGREE_COLOR_EG: ['agreeColorEg', '颜色示例'],
REPLY_NUMBER_TEXT: ['replyNumberText', '--> 回复高亮的阈值: '],
REPLY_NUMBER_INPUT: ['replyNumberInput', '(推荐: 50)'],
REPLY_COLOR_TEXT: ['replyColorText', '--> 回复高亮的颜色: '],
REPLY_COLOR_INPUT: ['replyColorInput', '(推荐: #2B65B7)'],
REPLY_COLOR_EG: ['replyColorEg', '颜色示例'],
COPY_CHECKBOX: ['copyCheckbox', '显示复制按钮(在提取到的链接后)'],
TEXT_COLOR_TEXT: ['textColorText', '隐藏文字的高亮颜色: '],
TEXT_COLOR_INPUT: ['textColorInput', '(推荐: #FF33CC)'],
TEXT_COLOR_EG: ['textColorEg', '颜色示例'],
LINK_COLOR_TEXT: ['linkColorText', '提取链接的文字颜色: '],
LINK_COLOR_INPUT: ['linkColorInput', '(推荐: #369)'],
LINK_COLOR_EG: ['linkColorEg', '颜色示例'],
SAVE_BUTTON: ['saveButton', '保存'],
CANCEL_BUTTON: ['cancelButton', '取消'],
FLOAT_CHECKBOX: ['floatCheckbox', '启用浮动模式'],
EXTRACT_CHECKBOX: ['extractCheckbox', '识别并提取文字中的链接(空心圆标记)'],
};
const URL_REG = /^[\S\s]*?((?:magnet:\?xt=|ftp:\/\/|ed2k:\/\/|thunder:\/\/|flashget:\/\/|qqdl:\/\/|xfplay:\/\/|https?:\/\/[\w-]*\.*[\w-]+\.+\w+)\S+)/i;
const DOWNLOAD_REG = /^[\S\s]*?((?:magnet:\?xt=|ed2k:\/\/|thunder:\/\/)\S+)/i;
const WWW_REG = /^[\S\s]*?(www\.[\w-]+\.[a-z]+[\w#=%+?/-]*)/i;
const BAIDUPAN_REG = /^https?:\/\/pan\.baidu\.com\/s(?:hare)?\/[\w=?-]+/i;
const BAIDUPAN_NOT_INCLUDE_CODE_REG = /^https?:\/\/pan\.baidu\.com\/s(?:hare)?\/[^#]+$/i;
const CODE_REG = /(?:提取)+[^a-z0-9解压]*([a-z0-9]{4})[^a-z0-9]*/i;
const BAIDUPAN_CODE_REG = /^(?:\S+\s+)?[^a-z0-9解压]*([a-z0-9]{4})[^a-z0-9]*(?:app)?[^a-z0-9]*$/i;
const SINGLE_CHAR_CODE_REG = /^[a-z0-9]$/i;
const MISSING_HEADER_BAIDUPAN_REG = /^[\S\s]*?[^/\w-]?(\/?s(?:hare)?\/[\w=?-]+)/i;
const MISSING_HEADER_BAIDUPAN_TEST_REG = /^([\w=?-]{6,50})\s+[a-z0-9]{4}$/i;
const PAN_REG = /^[\S\s]*?(pan\.baidu\.com\/s(?:hare)?\/[\w=?-]+)/i;
const HASH_REG = /^[^a-z0-9]*([a-z0-9]{40}|[a-z0-9]{32})[^a-z0-9]*$/i;
const CORE_VALUES_REG = /^(?:富强|民主|文明|和谐|自由|平等|公正|法治|爱国|敬业|诚信|友善){2,}$/i;
const BAIJIA_REG = /^[赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻福水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳唐罗薛伍余米贝姚孟顾尹江钟]{10,}$/i;
const PREFIX_LINK_REG = {
MAGNET: /^https?:\/\/www\.wnflb\d*\.com\/magnet:\?xt=.*$/i,
MAGNET_SWITCH: /^https?:\/\/www\.wnflb\d*\.com\//i,
};
const BASE_IMAGE_REG = /^https?:\/\/(data:)/i;
const FILTER_LINK_REG = {
PAN_TEXT: /^https?:\/\/pan\.baidu\.com\/(?:s|share|mbox)?\/[\w#?=-]*[^\w#?=-]+/i,
POJIE: /^https?:\/\/www\.52pojie\.cn\/?#?$/i,
POJIE_PHP: /^https?:\/\/www\.52pojie\.cn\/(?:forum|home|misc)\.php\?/i,
POJIE_HTML: /^https?:\/\/www\.52pojie\.cn\/(?:forum|thread)-\d+-\d+(?:-\d+)?\.html$/i,
FULIBA: /^https?:\/\/www\.wnflb\d*\.com\/?$/i,
FULIBA_PHP: /^https?:\/\/www\.wnflb\d*\.com\/(?:home|forum)\.php\?/i,
FULIBA_HTML: /^https?:\/\/www\.wnflb\d*\.com\/(?:thread|forum)-\d+-\d+(?:-\d+)?\.html$/i,
IMDB: /^https?:\/\/www\.imdb\.com\/title\//i,
DOUBAN: /^https?:\/\/movie\.douban\.com\/(?:subject|celebrity)\//i,
PHOTO_WEIBO: /^https?:\/\/photo\.weibo\.com\//i,
S_WEIBO: /^https?:\/\/s\.weibo\.com\/weibo\?q=/i,
BAIKE: /^https?:\/\/baike\.(?:so|baidu|sogou)\.com/i,
BILIBILI_APP: /^https?:\/\/app\.bilibili\.com/i,
ZHIYOO: /^https?:\/\/bbs\.zhiyoo\.com\/(?:forum|gforum)-\d+-\d+\.html/i,
TAG_3DM: /^https?:\/\/www\.3dmgame\.com\/tag\//i,
GAMES_3DM: /^https?:\/\/www\.3dmgame\.com\/games\/[^/]*\/?$/i,
TV432: /^https?:\/\/www\.tv432\.com\/search\.php\?searchword=/i,
VIIDII: /^https?:\/\/www\.viidii\.info\/\?/i,
DAYBOX: /^https?:\/\/www\.daybox\.net\/image\//i,
YIDIANZIXUN: /^https?:\/\/www\.yidianzixun\.com\/channel\//i,
SINA: /^https?:\/\/[\w-]*\.?sina\.com\.cn\/?/i,
};
const CORE_VALUES = '富强民主文明和谐自由平等公正法治爱国敬业诚信友善';
const BAIJIA_VALUES = {
"赵": "0",
"钱": "1",
"孙": "2",
"李": "3",
"周": "4",
"吴": "5",
"郑": "6",
"王": "7",
"冯": "8",
"陈": "9",
"褚": "a",
"卫": "b",
"蒋": "c",
"沈": "d",
"韩": "e",
"杨": "f",
"朱": "g",
"秦": "h",
"尤": "i",
"许": "j",
"何": "k",
"吕": "l",
"施": "m",
"张": "n",
"孔": "o",
"曹": "p",
"严": "q",
"华": "r",
"金": "s",
"魏": "t",
"陶": "u",
"姜": "v",
"戚": "w",
"谢": "x",
"邹": "y",
"喻": "z",
"福": "A",
"水": "B",
"窦": "C",
"章": "D",
"云": "E",
"苏": "F",
"潘": "G",
"葛": "H",
"奚": "I",
"范": "J",
"彭": "K",
"郎": "L",
"鲁": "M",
"韦": "N",
"昌": "O",
"马": "P",
"苗": "Q",
"凤": "R",
"花": "S",
"方": "T",
"俞": "U",
"任": "V",
"袁": "W",
"柳": "X",
"唐": "Y",
"罗": "Z",
"薛": ".",
"伍": "-",
"余": "_",
"米": "+",
"贝": "=",
"姚": "/",
"孟": "?",
"顾": "#",
"尹": "%",
"江": "&",
"钟": "*"
};
var highlight_config = {
highlight_enable: true,
agree_threshold: 0,
agree_color: '',
reply_threshold: 0,
reply_color: '',
copy_enable: true,
text_color: '',
link_color: '',
float_enable: false,
extract_enable: false,
};
var default_config = {
highlight_enable: true,
agree_threshold: 20,
agree_color: '#EE1B2E',
reply_threshold: 50,
reply_color: '#2B65B7',
copy_enable: true,
text_color: '#FF33CC',
link_color: '#369',
float_enable: false,
extract_enable: false,
};
var check_date = '';
function utf8_2_Str(utfs) {
let l = utfs.length;
let splited = [];
for (let i = 0; i < l; i++) {
if ((i & 1) === 0) {
splited.push('%')
}
splited.push(utfs[i])
}
return decodeURIComponent(splited.join(''))
}
function duo_2_Hex(duo) {
let hex = [];
let l = duo.length;
let i = 0;
while (i < l) {
if (duo[i] < 10) {
hex.push(duo[i])
} else {
if (duo[i] === 10) {
i++;
hex.push(duo[i] + 10)
} else {
i++;
hex.push(duo[i] + 6)
}
}
i++
}
return hex.map(v => v.toString(16).toUpperCase()).join('')
}
function values_Decode(encoded) {
let duo = [];
for (let c of encoded) {
let i = CORE_VALUES.indexOf(c);
if (i === -1) {
continue
} else if (i & 1) {
continue
} else {
duo.push(i >> 1)
}
}
let hexs = duo_2_Hex(duo);
let str;
try {
str = utf8_2_Str(hexs)
} catch (e) {
throw e;
}
return str
}
function get_Cut_Link_Text(link_text, float_enable = false) {
if (check_Mobile_Page()) {
return (link_text.length >= 35) ? (link_text.slice(0, 15) + ' ... ' + link_text.slice(-10)) : (link_text)
} else if (float_enable) {
return (link_text.length >= 50) ? (link_text.slice(0, 25) + ' ... ' + link_text.slice(-15)) : (link_text)
}
return (link_text.length >= 80) ? (link_text.slice(0, 45) + ' ... ' + link_text.slice(-25)) : (link_text)
}
function create_Link(link_href, list_style, float_enable = false) {
let link_li = document.createElement('li');
if (list_style) {
link_li.style.listStyleType = 'disc'
} else {
link_li.style.listStyleType = 'circle'
}
let link_a = document.createElement('a');
link_a.title = '点击访问';
link_a.href = encodeURI(link_href);
link_a.target = '_blank';
link_a.innerText = get_Cut_Link_Text(link_href, float_enable);
link_a.style.display = 'inline';
link_a.style.fontSize = '15px';
link_a.style.color = highlight_config.link_color;
link_a.style.whiteSpace = 'nowrap';
link_li.appendChild(link_a);
if (highlight_config.copy_enable) {
let copy_a = document.createElement('a');
copy_a.className = 'copy_btn';
copy_a.title = '复制链接';
copy_a.href = 'javascript:;';
copy_a.target = '_self';
copy_a.innerText = '复制';
copy_a.style.display = 'inline-block';
copy_a.style.fontSize = '15px';
copy_a.style.color = highlight_config.link_color;
copy_a.style.marginLeft = '20px';
copy_a.style.textDecoration = 'underline';
copy_a.addEventListener('click', function() {
GM_setClipboard(link_href, "text");
this.style.color = '#f60';
this.title = '复制成功'
});
link_li.appendChild(copy_a);
if (BAIDUPAN_REG.test(link_href) && (/#[a-z0-9]{4}$/i.test(link_href))) {
let code_value = /#([a-z0-9]{4})$/i.exec(link_href)[1];
let code_copy_a = document.createElement('a');
code_copy_a.className = 'code_copy_btn';
code_copy_a.title = '复制提取码';
code_copy_a.href = 'javascript:;';
code_copy_a.target = '_self';
code_copy_a.innerText = '复制提取码';
code_copy_a.style.display = 'inline-block';
code_copy_a.style.fontSize = '15px';
code_copy_a.style.color = highlight_config.link_color;
code_copy_a.style.marginLeft = '20px';
code_copy_a.style.textDecoration = 'underline';
code_copy_a.addEventListener('click', function() {
GM_setClipboard(code_value, "text");
this.style.color = '#f60';
this.title = '复制成功'
});
link_li.appendChild(code_copy_a)
}
}
return link_li
}
function manage_Prefix(input_link_array) {
let return_link_array = [];
$.each(input_link_array, function(_index, item) {
return_link_array.push(PREFIX_LINK_REG.MAGNET.test(item) ? item.replace(PREFIX_LINK_REG.MAGNET_SWITCH, '') : item)
});
return return_link_array
}
function manage_Text(text_array) {
let temp_array = [];
$.each(text_array, function(_index, item) {
if (URL_REG.test(item)) {
temp_array.push(URL_REG.exec(item)[1])
} else if (WWW_REG.test(item)) {
temp_array.push('http://' + WWW_REG.exec(item)[1])
} else if (PAN_REG.test(item)) {
temp_array.push('https://' + PAN_REG.exec(item)[1])
} else if (MISSING_HEADER_BAIDUPAN_REG.test(item)) {
let link_miss_value = MISSING_HEADER_BAIDUPAN_REG.exec(item)[1];
link_miss_value = (/^\//i.test(link_miss_value)) ? ('https://pan.baidu.com' + link_miss_value) : ('https://pan.baidu.com/' + link_miss_value);
temp_array.push(link_miss_value)
} else if (MISSING_HEADER_BAIDUPAN_TEST_REG.test(item)) {
temp_array.push('https://pan.baidu.com/s/' + MISSING_HEADER_BAIDUPAN_TEST_REG.exec(item)[1])
} else if (HASH_REG.test(item)) {
temp_array.push('magnet:?xt=urn:btih:' + HASH_REG.exec(item)[1])
}
});
return manage_Prefix(temp_array)
}
function decode_Link(input_link_array) {
$.each(input_link_array, function(index, item) {
input_link_array[index] = decodeURI(item)
});
return input_link_array
}
function baijia_Decode(encoded) {
let char_array = encoded.split("");
let str = '';
for (let i = 0; i < char_array.length; i++) {
str += BAIJIA_VALUES[char_array[i]]
}
if (URL_REG.test(str)) {
return str
} else {
return 'magnet:?xt=urn:btih:' + str
}
}
function decode_Core_Values(text_array) {
$.each(text_array, function(index, item) {
if (CORE_VALUES_REG.test(item)) {
text_array[index] = values_Decode(item)
} else if (BAIJIA_REG.test(item)) {
text_array[index] = baijia_Decode(item)
}
});
return text_array
}
function pick_Up_Baidupan_Code(text_array) {
let code_array = [];
let char_array = [];
for (let i = 0; i < text_array.length; i++) {
if (CODE_REG.test(text_array[i])) {
let code_value = CODE_REG.exec(text_array[i])[1];
if (code_array.indexOf(code_value) === -1) {
code_array.push(code_value)
}
} else if (BAIDUPAN_CODE_REG.test(text_array[i])) {
let paidupan_code_value = BAIDUPAN_CODE_REG.exec(text_array[i])[1];
if (code_array.indexOf(paidupan_code_value) === -1) {
code_array.push(paidupan_code_value)
}
} else if (SINGLE_CHAR_CODE_REG.test(text_array[i])) {
char_array.push(text_array[i])
}
}
while ((char_array.length > 0) && (char_array.length % 4 === 0)) {
let temp_code = char_array.splice(0, 4);
code_array.push(temp_code.join(""))
}
return code_array
}
function judge_Links(links_array, link_value) {
let status = true;
for (let i = 0; i < links_array.length; i++) {
if (get_Pure_Link(links_array[i], true).includes(get_Pure_Link(link_value, true))) {
status = false;
break
}
}
return status
}
function baidupan_Auto_Event(link_obj_array, baidu_obj_array, links_array, hide_text_array, show_text_array, node_text_array, float_enable = false) {
let link_array = [];
let link_text_array = [];
$.each(link_obj_array, function(_index, item) {
link_array.push(item.ele_value);
link_text_array.push(item.ele_container)
});
hide_text_array = decode_Core_Values(hide_text_array);
let concat_text_array = manage_Repeat_Array(decode_Link(hide_text_array));
let concat_link_array = manage_Repeat_Array(decode_Link(manage_Text(link_array.concat(concat_text_array))));
let general_text_array = show_text_array.concat(node_text_array.concat(link_text_array));
let index_a = [];
let code_b = pick_Up_Baidupan_Code(concat_text_array);
if (code_b.length > 0) {
for (let j = 0; j < concat_link_array.length; j++) {
if (BAIDUPAN_NOT_INCLUDE_CODE_REG.test(concat_link_array[j])) {
index_a.push(j)
}
}
if (code_b.length === index_a.length) {
for (let k = 0; k < index_a.length; k++) {
concat_link_array[index_a[k]] += '#' + code_b[k]
}
} else if (code_b.length === baidu_obj_array.length) {
for (let l = 0; l < baidu_obj_array.length; l++) {
if (float_enable) {
concat_link_array.push(baidu_obj_array[l].ele_value + '#' + code_b[l])
} else {
baidu_obj_array[l].ele.text(baidu_obj_array[l].ele_container + '#' + code_b[l]);
baidu_obj_array[l].ele.attr('href', baidu_obj_array[l].ele_value + '#' + code_b[l])
}
}
}
} else {
let code_c = pick_Up_Baidupan_Code(general_text_array);
if (code_c.length > 0) {
for (let j = 0; j < concat_link_array.length; j++) {
if (BAIDUPAN_NOT_INCLUDE_CODE_REG.test(concat_link_array[j])) {
index_a.push(j)
}
}
if (code_c.length === index_a.length) {
for (let k = 0; k < index_a.length; k++) {
concat_link_array[index_a[k]] += '#' + code_c[k]
}
} else if (code_c.length === baidu_obj_array.length) {
for (let l = 0; l < baidu_obj_array.length; l++) {
if (float_enable) {
concat_link_array.push(baidu_obj_array[l].ele_value + '#' + code_c[l])
} else {
baidu_obj_array[l].ele.text(baidu_obj_array[l].ele_container + '#' + code_c[l]);
baidu_obj_array[l].ele.attr('href', baidu_obj_array[l].ele_value + '#' + code_c[l])
}
}
}
}
}
let decode_array = [];
$.each(general_text_array, function(_index, item) {
if (CORE_VALUES_REG.test(item)) {
decode_array.push(values_Decode(item))
} else if (BAIJIA_REG.test(item)) {
decode_array.push(baijia_Decode(item))
} else if (HASH_REG.test(item)) {
decode_array.push('magnet:?xt=urn:btih:' + HASH_REG.exec(item)[1])
} else if (DOWNLOAD_REG.test(item)) {
decode_array.push(DOWNLOAD_REG.exec(item)[1])
}
});
decode_array = decode_Link(manage_Text(decode_array));
concat_link_array = concat_link_array.concat(decode_array);
let extract_array = [];
if (highlight_config.extract_enable) {
let general_link_array = decode_Link(manage_Text(general_text_array));
$.each(general_link_array, function(_index, item) {
if ((filter_Link(item)) && (judge_Links(links_array, item))) {
if (judge_Links(concat_link_array, item)) {
extract_array.push(item)
}
}
})
}
let back_obj = {
concat_link_array: manage_Repeat_Array(concat_link_array),
extract_link_array: manage_Repeat_Array(extract_array),
};
return back_obj
}
function create_Good_Boy_Button(link_obj, text_obj, node_text_array, float_enable = false) {
let back_obj = baidupan_Auto_Event(link_obj.link_obj_array, link_obj.baidu_obj_array, link_obj.links_array, text_obj.hide_text_array, text_obj.show_text_array, node_text_array, float_enable);
if ((back_obj.concat_link_array.length !== 0) || (back_obj.extract_link_array.length !== 0)) {
let good_boy_p = document.createElement('p');
good_boy_p.innerText = '好孩子看得见:';
good_boy_p.style.color = 'red';
good_boy_p.style.fontSize = '15px';
if (float_enable) {
let good_boy_div = document.createElement('div');
good_boy_div.className = 'goodBoyDiv';
good_boy_div.style.position = 'absolute';
good_boy_div.style.width = '430px';
good_boy_div.style.paddingLeft = '20px';
good_boy_div.style.paddingRight = '10px';
good_boy_div.style.marginLeft = '962px';
good_boy_div.style.marginTop = '-170px';
good_boy_div.style.border = '2px #CDCDCD solid';
good_boy_div.style.borderRadius = '8px';
let good_boy_ul = document.createElement('ul');
good_boy_ul.appendChild(good_boy_p);
good_boy_div.appendChild(good_boy_ul);
$.each(back_obj.concat_link_array, function(_index, item) {
good_boy_ul.appendChild(create_Link(item, true, true))
});
$.each(back_obj.extract_link_array, function(_index, item) {
good_boy_ul.appendChild(create_Link(item, false, true))
});
return good_boy_div
} else {
let good_boy_btn = document.createElement('ul');
good_boy_btn.className = 'goodBoy';
good_boy_btn.appendChild(good_boy_p);
$.each(back_obj.concat_link_array, function(_index, item) {
good_boy_btn.appendChild(create_Link(item, true))
});
$.each(back_obj.extract_link_array, function(_index, item) {
good_boy_btn.appendChild(create_Link(item, false))
});
return good_boy_btn
}
}
return ''
}
function filter_Link(input_link) {
let status = true;
if (input_link) {
$.each(FILTER_LINK_REG, function(_index, item) {
if (item.test(input_link)) {
status = false;
return false
}
})
} else {
status = false
}
return status
}
function manage_Repeat_Array(input_link_array) {
let output_link_array = [];
for (let i = 0, l = input_link_array.length; i < l; i++) {
for (let j = i + 1; j < l; j++) {
if (input_link_array[i] === input_link_array[j]) {
++i;
j = i
}
}
output_link_array.push(input_link_array[i])
}
return output_link_array
}
function get_Pure_Link(input_link, baidu_boolean = false) {
let output_link = input_link;
if (baidu_boolean && BAIDUPAN_REG.test(output_link)) {
if (/#[a-z0-9]{4}$/i.test(output_link)) {
output_link = output_link.replace(/#[a-z0-9]{4}$/i, '')
}
}
return decodeURI(output_link.replace(/(^(?:\s+)?(?:\[url\])?(?:\s+)?(?:https?:\/\/)?|(?:\/+)?(?:\s+)?(?:\[\/url\])?$|%C2%A0$)/gi, '').replace(/%C2%A0/gi, '%20'))
}
function contrast_Text_And_Link(text_value, link_value) {
let status = true;
text_value = get_Pure_Link(text_value);
link_value = get_Pure_Link(link_value);
if (/\s...\s/i.test(text_value)) {
status = false
} else if (text_value === link_value) {
status = false
}
return status
}
function find_Link(container) {
let link = container.find('a').not($('div.aimg_tip a'));
let temp_obj = {
link_obj_array: [],
baidu_obj_array: [],
links_array: [],
};
for (let i = 0; i < link.length; i++) {
if (link.eq(i).find('img.zoom').length === 1) {
let zoom_img = link.eq(i).find('img.zoom');
if (!/^data:/i.test(zoom_img.attr('src'))) {
continue
}
}
let temp_link = link.eq(i).attr('href');
if (filter_Link(temp_link)) {
let temp_img = link.eq(i).find('img');
if ((temp_img.length === 0) || ((temp_img.length !== 0) && (temp_img.attr('src') !== temp_link))) {
let temp_text = link.eq(i).text().replace(/^\s+|\s+$/gi, '');
if (contrast_Text_And_Link(temp_text, temp_link)) {
let link_obj = {
ele_value: temp_link,
ele_container: temp_text,
ele: link.eq(i),
};
temp_obj.link_obj_array.push(link_obj)
} else if (BAIDUPAN_NOT_INCLUDE_CODE_REG.test(temp_link)) {
let baidu_obj = {
ele_value: temp_link,
ele_container: temp_text,
ele: link.eq(i),
};
temp_obj.baidu_obj_array.push(baidu_obj)
}
}
temp_obj.links_array.push(temp_link)
}
}
return temp_obj
}
function judge_Color(rgb_color_value) {
if (/rgb\(/i.test(rgb_color_value)) {
let rgb_value = rgb_color_value.replace('rgb(', '').replace(')', '');
let rgb_value_array = rgb_value.split(',');
let gray_level = rgb_value_array[0] * 0.299 + rgb_value_array[1] * 0.587 + rgb_value_array[2] * 0.114;
return gray_level > 192
} else if (/rgba\(/i.test(rgb_color_value)) {
let rgba_value = rgb_color_value.replace('rgba(', '').replace(')', '');
let rgba_value_array = rgba_value.split(',');
if (rgba_value_array[3] <= 0.2) {
return true
} else {
let gray_level_2 = rgba_value_array[0] * 0.299 + rgba_value_array[1] * 0.587 + rgba_value_array[2] * 0.114;
return gray_level_2 > 192
}
}
return false
}
function rgb_To_Rgba(color_string) {
let color_value = color_string.match(/\d+/g);
if (color_value.length === 3) {
return 'rgba(' + color_value[0] + ', ' + color_value[1] + ', ' + color_value[2] + (', 1)')
}
return color_string
}
function display_Text(container, new_text_color, new_text_background_color) {
let text = container.find('font').not('.quote font').not('font:has(.aimg_tip)');
let temp_obj = {
hide_text_array: [],
show_text_array: [],
};
for (let i = 0; i < text.length; i++) {
let temp_text = text.eq(i).text().replace(/^\s+|\s+$/gi, '');
if (!/^\s*$/i.test(temp_text)) {
let text_color = text.eq(i).css('color');
let text_background_color = text.eq(i).css('background-color');
if ((judge_Color(text_color)) && (judge_Color(text_background_color))) {
text.eq(i).css('color', new_text_color);
temp_obj.hide_text_array.push(temp_text)
} else if (rgb_To_Rgba(text_background_color) === rgb_To_Rgba(text_color)) {
text.eq(i).css('background-color', new_text_background_color);
text.eq(i).css('color', new_text_color);
temp_obj.hide_text_array.push(temp_text)
} else if ((!judge_Color(text_background_color)) && (!judge_Color(text_color))) {
text.eq(i).css('background-color', new_text_background_color);
text.eq(i).css('color', new_text_color);
temp_obj.hide_text_array.push(temp_text)
} else {
if (!temp_obj.show_text_array.includes(temp_text)) {
temp_obj.show_text_array.push(temp_text)
}
}
}
}
return temp_obj
}
function analysis_Text(dom_point) {
let node_list = dom_point.childNodes;
let node_text_array = [];
for (let i = 0; i < node_list.length; i++) {
if (node_list[i].nodeType === 3) {
let temp_text = node_list[i].nodeValue.replace(/^\s+|\s+$/gi, '');
if (!/^\s*$/i.test(temp_text)) {
node_text_array.push(temp_text)
}
} else if ((node_list[i].nodeType === 1) && (!node_list[i].className.includes('quote')) && (!node_list[i].className.includes('pstatus')) && (!node_list[i].className.includes('aimg_tip')) && (!node_list[i].className.includes('blockcode')) && (node_list[i].nodeName !== 'FONT') && (node_list[i].nodeName !== 'A') && (node_list[i].childNodes.length > 0)) {
let recursive_array = analysis_Text(node_list[i]);
for (let j = 0; j < recursive_array.length; j++) {
node_text_array.push(recursive_array[j])
}
}
}
return node_text_array
}
function check_Mobile_Page() {
return /手机版(?:\s+-\s+powered\s+by\s+discuz!)?$/i.test($('head title').text())
}
function get_Now_Date() {
let now = new Date();
return now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate()
}
function highlight_Post() {
let common_btn = $('tbody .common, tbody .new, tbody .lock');
for (let i = 0; i < common_btn.length; i++) {
let agree_num = common_btn.eq(i).find('font:first').text();
if (agree_num) {
agree_num = Number(agree_num.replace('+', ''));
if (agree_num >= highlight_config.agree_threshold) {
common_btn.eq(i).find('.xst').css({
'color': highlight_config.agree_color,
'font-weight': 'bold',
});
continue
}
}
let reply_num = common_btn.eq(i).parent().find('td.num .xi2:first').text();
if (reply_num) {
reply_num = Number(reply_num);
if (reply_num >= highlight_config.reply_threshold) {
common_btn.eq(i).find('.xst').css({
'color': highlight_config.reply_color,
'font-weight': 'bold',
})
}
}
}
}
function insert_Checkbox(ul_node, li_array, check_enable_value) {
let temp_li = document.createElement('li');
temp_li.innerHTML = '<label style="vertical-align: middle;"><input id="' + li_array[0] + '" type="checkbox" style="margin-right: 5px; margin-bottom: 6px;"' + (check_enable_value === true ? 'checked' : '') + '>' + li_array[1] + '</label>';
ul_node.appendChild(temp_li)
}
function insert_Input(ul_node, text_array, input_array, input_value, eg_array) {
let temp_li = document.createElement('li');
let text_span = document.createElement('span');
text_span.id = text_array[0];
text_span.innerText = text_array[1];
text_span.style.marginLeft = '5px';
temp_li.appendChild(text_span);
let temp_input = document.createElement('input');
temp_input.id = input_array[0];
temp_input.placeholder = input_array[1];
temp_input.value = input_value;
temp_input.style.width = '120px';
temp_li.appendChild(temp_input);
if (arguments.length === 5) {
let eg_span = document.createElement('span');
eg_span.id = eg_array[0];
eg_span.innerText = eg_array[1];
eg_span.style.marginLeft = '5px';
eg_span.style.color = input_value;
temp_input.oninput = function() {
eg_span.style.color = this.value
};
temp_li.appendChild(eg_span)
}
ul_node.appendChild(temp_li)
}
function create_Setting_Tag() {
let wrap_div = document.createElement('div');
wrap_div.id = SETTING_VALUE.WRAP_DIV[0];
wrap_div.setAttribute('style', 'position: fixed; top: 4vw; right: 2vw; z-index: 9999; background-color: #fff; text-align: left; display: block; padding: 0; margin: 0; border: 1px solid #a0a0a0; border-radius: 3px; color: #000; font-size: 13px; display: block;');
let main_fieldset = document.createElement('fieldset');
main_fieldset.id = SETTING_VALUE.MAIN_FIELDSET[0];
main_fieldset.setAttribute('style', 'border: 3px solid #ccc; border-radius: 3px; padding: 4px 9px 6px 9px; margin: 8px; min-width: 300px; width: auto; height: auto;');
wrap_div.appendChild(main_fieldset);
let headline_legend = document.createElement('legend');
headline_legend.id = SETTING_VALUE.HEADLINE_LEGEND[0];
headline_legend.innerText = SETTING_VALUE.HEADLINE_LEGEND[1];
main_fieldset.appendChild(headline_legend);
let tag_ul = document.createElement('ul');
tag_ul.id = SETTING_VALUE.TAG_UL[0];
tag_ul.setAttribute('style', 'list-style: none; padding-left: 0;');
main_fieldset.appendChild(tag_ul);
insert_Checkbox(tag_ul, SETTING_VALUE.HIGHLIGHT_CHECKBOX, highlight_config.highlight_enable);
insert_Input(tag_ul, SETTING_VALUE.AGREE_NUMBER_TEXT, SETTING_VALUE.AGREE_NUMBER_INPUT, highlight_config.agree_threshold);
insert_Input(tag_ul, SETTING_VALUE.AGREE_COLOR_TEXT, SETTING_VALUE.AGREE_COLOR_INPUT, highlight_config.agree_color, SETTING_VALUE.AGREE_COLOR_EG);
insert_Input(tag_ul, SETTING_VALUE.REPLY_NUMBER_TEXT, SETTING_VALUE.REPLY_NUMBER_INPUT, highlight_config.reply_threshold);
insert_Input(tag_ul, SETTING_VALUE.REPLY_COLOR_TEXT, SETTING_VALUE.REPLY_COLOR_INPUT, highlight_config.reply_color, SETTING_VALUE.REPLY_COLOR_EG);
let br = document.createElement('li');
br.innerHTML = '--------------------------------------------------------';
tag_ul.appendChild(br);
insert_Checkbox(tag_ul, SETTING_VALUE.FLOAT_CHECKBOX, highlight_config.float_enable);
insert_Checkbox(tag_ul, SETTING_VALUE.EXTRACT_CHECKBOX, highlight_config.extract_enable);
insert_Checkbox(tag_ul, SETTING_VALUE.COPY_CHECKBOX, highlight_config.copy_enable);
insert_Input(tag_ul, SETTING_VALUE.TEXT_COLOR_TEXT, SETTING_VALUE.TEXT_COLOR_INPUT, highlight_config.text_color, SETTING_VALUE.TEXT_COLOR_EG);
insert_Input(tag_ul, SETTING_VALUE.LINK_COLOR_TEXT, SETTING_VALUE.LINK_COLOR_INPUT, highlight_config.link_color, SETTING_VALUE.LINK_COLOR_EG);
let save_button = document.createElement('button');
save_button.id = SETTING_VALUE.SAVE_BUTTON[0];
save_button.type = 'button';
save_button.setAttribute('style', 'position: relative; float: right; margin-right: 5px; margin-top: 5px; cursor: pointer;');
save_button.innerText = SETTING_VALUE.SAVE_BUTTON[1];
save_button.addEventListener('click', function() {
highlight_config.highlight_enable = document.getElementById(SETTING_VALUE.HIGHLIGHT_CHECKBOX[0]).checked;
highlight_config.agree_threshold = document.getElementById(SETTING_VALUE.AGREE_NUMBER_INPUT[0]).value;
highlight_config.agree_color = document.getElementById(SETTING_VALUE.AGREE_COLOR_INPUT[0]).value;
highlight_config.reply_threshold = document.getElementById(SETTING_VALUE.REPLY_NUMBER_INPUT[0]).value;
highlight_config.reply_color = document.getElementById(SETTING_VALUE.REPLY_COLOR_INPUT[0]).value;
highlight_config.copy_enable = document.getElementById(SETTING_VALUE.COPY_CHECKBOX[0]).checked;
highlight_config.text_color = document.getElementById(SETTING_VALUE.TEXT_COLOR_INPUT[0]).value;
highlight_config.link_color = document.getElementById(SETTING_VALUE.LINK_COLOR_INPUT[0]).value;
highlight_config.float_enable = document.getElementById(SETTING_VALUE.FLOAT_CHECKBOX[0]).checked;
highlight_config.extract_enable = document.getElementById(SETTING_VALUE.EXTRACT_CHECKBOX[0]).checked;
GM_setValue('highlight_config', highlight_config);
location.reload()
});
tag_ul.appendChild(save_button);
let cancel_button = document.createElement('button');
cancel_button.id = SETTING_VALUE.CANCEL_BUTTON[0];
cancel_button.type = 'button';
cancel_button.setAttribute('style', 'position: relative; float: left; margin-left: 5px; margin-top:5px; cursor: pointer;');
cancel_button.innerText = SETTING_VALUE.CANCEL_BUTTON[1];
cancel_button.addEventListener('click', function(e) {
document.getElementById(SETTING_VALUE.WRAP_DIV[0]).style.display = 'none';
e.stopPropagation()
});
tag_ul.appendChild(cancel_button);
return wrap_div
}
function init() {
let old_url = location.href;
if (check_Mobile_Page()) {
if (highlight_config.highlight_enable) {
if ((old_url.indexOf('mod=forumdisplay') !== -1) || (/forum-\d+-\d+\.html/i.test(old_url))) {
let li_btn = $('ul li');
$.each(li_btn, function(_index, item) {
let reply_num = $(item).find('.num').text();
if (reply_num) {
reply_num = Number(reply_num);
if (reply_num >= highlight_config.reply_threshold) {
$(item).find('> a').css({
'color': highlight_config.reply_color,
'font-weight': 'bold',
})
}
}
});
let xg1_btn = $('div.bm_c');
$.each(xg1_btn, function(_index, item) {
let xg1_reply_num = /回(\d+)/.exec($(item).find('span.xg1:first').text());
if (xg1_reply_num) {
xg1_reply_num = Number(xg1_reply_num[1]);
if (xg1_reply_num >= highlight_config.reply_threshold) {
$(item).find('> a').css({
'color': highlight_config.reply_color,
'font-weight': 'bold',
})
}
}
})
}
}
if ((old_url.indexOf('mod=viewthread') !== -1) || (/thread-\d+-\d+(?:-\d+)?\.html/i.test(old_url))) {
let message_btn = $('div.message');
for (let i = 0; i < message_btn.length; i++) {
message_btn.eq(i).append(create_Good_Boy_Button(find_Link(message_btn.eq(i)), display_Text(message_btn.eq(i), highlight_config.text_color, '#efefef'), analysis_Text(message_btn.eq(i)[0])))
}
let pbody_btn = $('div.pbody');
for (let j = 0; j < pbody_btn.length; j++) {
pbody_btn.eq(j).append(create_Good_Boy_Button(find_Link(pbody_btn.eq(j)), display_Text(pbody_btn.eq(j), highlight_config.text_color, '#fff'), analysis_Text(pbody_btn.eq(j)[0])))
}
}
Promise.all([GM_getValue('check_date')]).then(function(data) {
if (data[0] !== undefined) {
check_date = data[0]
} else {
check_date = '2000-1-1'
}
let now_date = get_Now_Date();
if (now_date !== check_date) {
GM_setValue('check_date', now_date);
let check_btn;
if ($('.bg > a').length !== 0) {
check_btn = $('.bg > a')
} else {
check_btn = $('div.wp > a')
}
if (check_btn.text() === '签到领奖') {
check_btn[0].click()
}
}
})
} else {
let html_background_color = $('html').css('background-color');
if (highlight_config.highlight_enable) {
if ((old_url.indexOf('mod=forumdisplay') !== -1) || (/forum-\d+-\d+\.html/i.test(old_url))) {
highlight_Post();
try {
let observer = new MutationObserver(function() {
highlight_Post()
});
let listener_container = document.querySelector("body");
let option = {
'childList': true,
'subtree': true
};
observer.observe(listener_container, option)
} catch (e) {
console.log(e)
}
}
}
if ((old_url.indexOf('mod=viewthread') !== -1) || (/thread-\d+-\d+(?:-\d+)?\.html/i.test(old_url))) {
$.each($('td.t_f img'), function(_index, item) {
let base_src = $(item).attr('file');
if (BASE_IMAGE_REG.test(base_src)) {
base_src = base_src.replace(BASE_IMAGE_REG, '$1');
$(item).attr('file', base_src);
item.src = base_src
}
});
let td_btn = $('td.t_f');
if (highlight_config.float_enable) {
let favatar_btn = $('div.favatar').filter(function() {
return $(this).closest('tbody').find('td div.locked').length === 0
});
for (let j = 0; j < td_btn.length; j++) {
favatar_btn.eq(j).append(create_Good_Boy_Button(find_Link(td_btn.eq(j)), display_Text(td_btn.eq(j), highlight_config.text_color, html_background_color), analysis_Text(td_btn.eq(j)[0]), true))
}
} else {
let main_btn = $('div.cm');
for (let k = 0; k < td_btn.length; k++) {
main_btn.eq(k).after(create_Good_Boy_Button(find_Link(td_btn.eq(k)), display_Text(td_btn.eq(k), highlight_config.text_color, html_background_color), analysis_Text(td_btn.eq(k)[0])))
}
}
}
let check_btn = $('a#fx_checkin_topb');
if (check_btn.attr('initialized') !== 'true') {
check_btn.click()
}
}
}
Promise.all([GM_getValue('highlight_config')]).then(function(data) {
if (data[0] !== undefined) {
highlight_config = data[0]
} else {
highlight_config = default_config
}
try {
GM_registerMenuCommand('好孩子看得见设置', function() {
if (document.getElementById(SETTING_VALUE.WRAP_DIV[0])) {
if (document.getElementById(SETTING_VALUE.WRAP_DIV[0]).style.display === 'none') {
document.getElementById(SETTING_VALUE.WRAP_DIV[0]).style.display = 'block'
} else {
document.getElementById(SETTING_VALUE.WRAP_DIV[0]).style.display = 'none'
}
} else {
let hd = document.getElementById('hd');
if (hd) {
hd.appendChild(create_Setting_Tag())
} else {
let header = document.getElementsByClassName('header')[0];
if (header) {
header.appendChild(create_Setting_Tag())
} else {
let hd_header = document.getElementsByClassName('hd')[0];
hd_header.appendChild(create_Setting_Tag())
}
}
}
})
} catch (e) {
console.log(e)
}
init()
}).
catch (function(except) {
console.log(except)
})
})();