// ==UserScript==
// @name 福利吧论坛好孩子看得见
// @namespace https://greasyfork.org/zh-CN/users/193133-pana
// @homepage https://www.sailboatweb.com
// @version 6.2.0
// @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.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.2.0'],
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', '启用浮动模式'],
};
const URL_REG = /^[\S\s]*((?:https?:\/\/[\w-]*\.*[\w-]+\.+\w+|magnet:\?xt=|ftp:\/\/|ed2k:\/\/|thunder:\/\/|flashget:\/\/|qqdl:\/\/|xfplay:\/\/)\S+)/i;
const DOWNLOAD_REG = /^[\S\s]*((?:magnet:\?xt=|ed2k:\/\/|thunder:\/\/)\S+)/i;
const WWW_REG = /^[\S\s]*(www\.[\w-]+\.[a-z]+\S*)/i;
const BAIDUPAN_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 = /^[^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]*(\/?s(?:hare)?\/\S+)/i;
const MISSING_HEADER_BAIDUPAN_TEST_REG = /^[\S\s]*([a-z0-9_-]+)\s+[a-z0-9]{4}$/i;
const PAN_REG = /^[\S\s]*(pan\.baidu\.com\/s(?:hare)?\/\S+)/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 FILTER_LINK_REG = {
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,
};
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
};
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
};
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 > 60) ? (link_text.slice(0, 30) + ' ... ' + link_text.slice(-20)) : (link_text)
}
return (link_text.length > 80) ? (link_text.slice(0, 45) + ' ... ' + link_text.slice(-25)) : (link_text)
}
function create_Link(link_href, float_enable = false) {
let link_li = document.createElement('li');
link_li.style.listStyleType = 'disc';
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';
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';
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 baidupan_Auto_Event(link_obj_array, baidu_obj_array, hide_text_array, show_text_array, node_text_array) {
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(link_text_array.concat(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);
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_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++) {
concat_link_array.push(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_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++) {
concat_link_array.push(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)));
$.each(decode_array, function(_index, item) {
concat_link_array.push(item)
});
return manage_Repeat_Array(concat_link_array)
}
function create_Good_Boy_Button(link_obj, text_obj, node_text_array, float_enable = false) {
let concat_array = baidupan_Auto_Event(link_obj.link_obj_array, link_obj.baidu_obj_array, text_obj.hide_text_array, text_obj.show_text_array, node_text_array);
if ((concat_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 = '-270px';
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(concat_array, function(_index, item) {
good_boy_ul.appendChild(create_Link(item, 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(concat_array, function(_index, item) {
good_boy_btn.appendChild(create_Link(item))
});
return good_boy_btn
}
}
return ''
}
function filter_Link(input_link) {
let status = true;
$.each(FILTER_LINK_REG, function(_index, item) {
if (item.test(input_link)) {
status = false;
return 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) {
return input_link.replace(/(^\s+|^https?:\/\/|\/+$|\s+$|%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);
text_value = decodeURI(text_value);
link_value = decodeURI(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')).not($('a:has(img.zoom)'));
let temp_obj = {
link_obj_array: [],
baidu_obj_array: [],
};
for (let i = 0; i < link.length; i++) {
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_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)
}
}
}
}
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');
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)) {
if (judge_Color(text.eq(i).css('color'))) {
text.eq(i).css('color', new_text_color);
temp_obj.hide_text_array.push(temp_text)
}
if (rgb_To_Rgba(text.eq(i).css('background-color')) === rgb_To_Rgba(text.eq(i).css('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.eq(i).css('background-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_text && !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].nodeName !== 'FONT') && (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');
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.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;
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))) {
let favatar_btn = $('div.favatar');
let main_btn = $('div.cm');
let td_btn = $('td.t_f');
if (highlight_config.float_enable) {
for (let j = 0; j < favatar_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 {
for (let k = 0; k < main_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)
})
})();