福利吧论坛好孩子看得见

好孩子才看得见,支持移动端

As of 2019-08-27. See the latest version.

// ==UserScript==
// @name         福利吧论坛好孩子看得见
// @namespace    https://greasyfork.org/zh-CN/users/193133-pana
// @homepage     https://www.sailboatweb.com
// @version      4.3.4
// @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
// @note         社会主义核心价值观编码: https://github.com/sym233/core-values-encoder
// ==/UserScript==

(function() {
	'use strict';
	const URL_REG = /^(链接:|链接:)?(\s)*((https?:\/\/|magnet:\?xt=|ftp:\/\/|ed2k:\/\/|thunder:\/\/|flashget:\/\/|qqdl:\/\/|xfplay:\/\/)\S+)/i;
	const WWW_REG = /^(链接:|链接:)?(\s)*(www\.\S+)/i;
	const BAIDUPAN_REG = /^https?:\/\/pan\.baidu\.com\/s(hare)?\/./i;
	const CODE_REG = /^(链接:|链接:)?(\s)*(.*提取码|\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(hare)?\/\S+)/i;
	const MISSING_HEADER_BAIDUPAN_TEST_REG = /^(链接:|链接:)?(\s)*([a-z0-9_-]+)\s+[a-z0-9]{4}$/i;
	const PAN_REG = /^(链接:|链接:)?(\s)*(pan\.baidu\.com\/s(hare)?\/\S+)/i;
	const HASH_REG = /^[a-z0-9]{32}$|^[a-z0-9]{40}$/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-\d+-\d+(-\d)?\.html$/i,
		DAYBOX: /^https?:\/\/www\.daybox\.net\/image\//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,
	};
	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",
		"薛": ".",
		"伍": "-",
		"余": "_",
		"米": "+",
		"贝": "=",
		"姚": "/",
		"孟": "?",
		"顾": "#",
		"尹": "%",
		"江": "&",
		"钟": "*"
	};

	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) {
		if (check_Mobile_Page()) {
			return (link_text.length > 35) ? (link_text.slice(0, 15) + ' ... ' + link_text.slice(-10)) : (link_text)
		}
		return (link_text.length > 80) ? (link_text.slice(0, 45) + ' ... ' + link_text.slice(-25)) : (link_text)
	}
	function create_Link(link_href) {
		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);
		link_a.style.display = 'inline-block';
		link_a.style.fontSize = '15px';
		link_a.style.color = 'blue';
		link_a.style.whiteSpace = 'nowrap';
		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 = 'blue';
		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(link_a);
		link_li.appendChild(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)[3])
			} else if (WWW_REG.test(item)) {
				temp_array.push('http://' + WWW_REG.exec(item)[3])
			} else if (PAN_REG.test(item)) {
				temp_array.push('https://' + PAN_REG.exec(item)[3])
			} else if (MISSING_HEADER_BAIDUPAN_REG.test(item)) {
				let link_miss_value = MISSING_HEADER_BAIDUPAN_REG.exec(item)[3];
				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)[3])
			} else if (HASH_REG.test(item)) {
				temp_array.push('magnet:?xt=urn:btih:' + item)
			}
		});
		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 (CODE_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])[4];
				if (code_array.indexOf(code_value) === -1) {
					code_array.push(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++) {
					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_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++) {
						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:' + item)
			}
		});
		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) {
		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_btn = document.createElement('ul');
			good_boy_btn.className = 'goodBoy';
			let good_boy_p = document.createElement('p');
			good_boy_p.innerText = '好孩子看得见:';
			good_boy_p.style.color = 'red';
			good_boy_p.style.fontSize = '15px';
			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();
					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++) {
			if (judge_Color(text.eq(i).css('color'))) {
				text.eq(i).css('color', new_text_color);
				temp_obj.hide_text_array.push(text.eq(i).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(text.eq(i).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(text.eq(i).text())
			} else {
				let temp_text = text.eq(i).text().replace(/^\s+|\s+$/gi, '');
				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(container) {
		let node_list = container[0].childNodes;
		let node_text_array = [];
		for (let i = 0; i < node_list.length; i++) {
			if (node_list[i].nodeType === 3) {
				if (!/^\s+$/i.test(node_list[i].nodeValue)) {
					node_text_array.push(node_list[i].nodeValue.replace(/^\s+|\s+$/gi, ''))
				}
			}
		}
		return node_text_array
	}
	function check_Mobile_Page() {
		return /手机版(\s+-\s+powered\s+by\s+discuz!)?$/i.test($('head title').text())
	}
	function init() {
		if (check_Mobile_Page()) {
			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), '#ff33cc', '#efefef'), analysis_Text(message_btn.eq(i))))
			}
		} else {
			let main_btn = $('div.cm');
			let td_btn = $('td.t_f');
			for (let i = 0; i < main_btn.length; i++) {
				main_btn.eq(i).after(create_Good_Boy_Button(find_Link(td_btn.eq(i)), display_Text(td_btn.eq(i), '#ff33cc', 'white'), analysis_Text(td_btn.eq(i))))
			}
			let check_btn = $('a#fx_checkin_topb');
			if (check_btn.attr('initialized') !== 'true') {
				check_btn.click()
			}
		}
	}
	init()
})();