// ==UserScript==
// @name         骚扰拦截
// @version      1.4.15
// @namespace    airbash/AnnoyancesInterception
// @homepageURL  https://github.com/AirBashX/UserScript
// @author       airbash
// @description  手机、电脑全平台通用:自动拦截或删除`下载弹窗`、`悬浮按钮`等影响用户体验的元素;长期维护:CSDN、简书、知乎、知乎专栏、百度搜索、百家号、百度贴吧、百度文库、百度新闻、新浪新闻、腾讯视频、优酷视频、爱奇艺、好看视频、哔哩哔哩、B站专栏、B站笔记、西瓜视频、抖音、丁香园、健康界、微博、新浪财经、东方财富网、电子发烧友、人民网、新京报、观察者网、澎湃新闻、凤凰新闻、网易新闻、今日头条、东方资讯、虎嗅、虎扑、豆瓣、中关村在线、太平洋电脑、太平洋汽车网、汽车之家、太平洋汽车网、taptap、it之家、360doc、开源中国、segmentfault、W3CSchool、阿里云开发者社区、腾讯云开发者社区、华为云开发者社区、36氪、雪球、天眼查、站酷、小红书、中国知网、装备前线、必应搜索、什么值得买
// @match        *://*.csdn.net/*
// @match      	 *://*.jianshu.com/*
// @match        *://juejin.cn/*
// @match        *://*.zhihu.com/*
// @match        *://tieba.baidu.com/*
// @match        *://baijiahao.baidu.com/s*
// @match        *://mbd.baidu.com/newspage/data/*
// @match        *://news.baidu.com/news*
// @match        *://m.baidu.com/sf_baijiahao/*
// @match        *://view.inews.qq.com/*
// @match        *://xw.qq.com/*
// @match        *://m.sohu.com/a/*
// @match        *://m.v.qq.com/*
// @match        *://*.youku.com/*
// @match        *://*.iqiyi.com/*
// @match        *://haokan.baidu.com/*
// @match        *://*.1905.com/*
// @match        *://*.baidu.com/*
// @match        *://*.bilibili.com/*
// @match        *://3g.dxy.cn/*
// @match        *://www.cn-healthcare.com/*
// @match        *://*.sina.cn/*
// @match        *://m.weibo.cn/*
// @match        *://wap.eastmoney.com/*
// @match        *://mguba.eastmoney.com/*
// @match        *://*.ixigua.com/*
// @match        *://www.douyin.com/*
// @match        *://m.elecfans.com/*
// @match        *://app.people.cn/*
// @match        *://m.bjnews.com.cn/detail/*
// @match        *://*.guancha.cn/*
// @match        *://m.thepaper.cn/newsDetail_forward*
// @match        *://*.ifeng.com/*
// @match        *://m.163.com/*
// @match        *://3g.163.com/*
// @match        *://m.toutiao.com/*
// @match        *://www.toutiao.com/*
// @match        *://mini.eastday.com/nsa/*
// @match        *://m.huxiu.com/*
// @match        *://m.hupu.com/*
// @match        *://m.douban.com/*
// @match        *://g.pconline.com.cn/*
// @match        *://m.zol.com.cn/*
// @match        *://wap.zol.com.cn/*
// @match        *://www.autohome.com.cn/*
// @match        *://*.m.autohome.com.cn/*
// @match        *://m.autohome.com.cn/*
// @match        *://m.pcauto.com.cn/*
// @match        *://www.taptap.cn/*
// @match        *://m.taptap.cn/*
// @match        *://m.ithome.com/*
// @match        *://www.360doc.com/content/*
// @match        *://www.oschina.net/*
// @match        *://developer.aliyun.com/article/*
// @match        *://huaweicloud.csdn.net/*
// @match        *://m.36kr.com/p/*
// @match        *://xueqiu.com/*
// @match        *://segmentfault.com/q/*
// @match        *://www.w3cschool.cn/*
// @match        *://m.tianyancha.com/*
// @match        *://*.zcool.com.cn/*
// @match        *://m.ximalaya.com/*
// @match        *://www.xiaohongshu.com/*
// @match        *://wap.cnki.net/*
// @match        *://www.zfrontier.com/*
// @match        *://*.m.smzdm.com/*
// @icon         data:image/png;base64,[encoded data, 6300 characters]
// @run-at       document-body
// @grant        none
// @license      GPL-3.0
// @downloadURL https://update.greasyfork.org/scripts/440871/%E9%AA%9A%E6%89%B0%E6%8B%A6%E6%88%AA.user.js
// @updateURL https://update.greasyfork.org/scripts/440871/%E9%AA%9A%E6%89%B0%E6%8B%A6%E6%88%AA.meta.js
// ==/UserScript==

(function () {
	"use strict";

	/**
	 * 规则列表
	 * @type {name/url/items}
	 */
	const websites = [
		{
			name: "CSDN",
			url: "csdn.net",
			items: [
				//下载弹窗
				".weixin-shadowbox",
				//悬浮按钮:打开:狐猴浏览器中的bug
				".feed-Sign-weixin",
				//悬浮按钮:APP内打开+登录/打开注册(主页)
				".feed-Sign-span",
				//PC端:弹窗:学生认证
				"#csdn-highschool-window",
				//PC端:登录弹窗(顶部)
				"#csdn-toolbar-profile-nologin",
				//PC端:登录弹窗(底部)
				".passport-login-tip-container",
			],
			fun: function () {
				/**
				 * PC端:屏蔽登录弹窗
				 * @param      {list}  mutationsList  The mutations list
				 */
				let removeLoginNotice = function (mutationsList) {
					for (let mutation of mutationsList) {
						for (let node of mutation.addedNodes) {
							if (document.querySelector(".passport-login-container")) {
								//有登陆弹窗时:模拟点击关闭按钮
								let button = node.querySelector("img");
								if (button) {
									if (LoginFlag == true) {
										button.click();
									} else {
										LoginFlag = true;
									}
									return;
								}
							}
						}
					}
				};

				let loginBtn = document.querySelector(".toolbar-btn-login>.toolbar-btn-loginfun");
				//未登录:
				if (loginBtn) {
					//添加事件,不拦截
					loginBtn.addEventListener("click", function () {
						LoginFlag = false;
					});
					//执行监听
					let observer = new MutationObserver(removeLoginNotice);
					observer.observe(document, { childList: true, subtree: true });
				}
				//移动版登录弹窗
				if (document.querySelector(".toolbarBack")) {
					addStyle(".passport-login-container {display: none !important}");
				}
			},
		},
		{
			name: "简书",
			url: "jianshu.com",
			items: [
				//下载弹窗
				".download-app-guidance",
				//悬浮按钮:打开App,看更多相似好文
				".call-app-btn",
				//悬浮按钮:打开App,看更多好文(首页)
				".index_call-app-btn",
				//PC端:透明遮挡
				"._23ISFX-mask",
				//PC端:登录弹窗
				"._23ISFX-wrap",
			],
			overflow: true,
		},
		{
			name: "掘金",
			url: "juejin.cn",
			items: [
				//悬浮按钮:APP内打开
				".open-button",
				//下载弹窗
				".app-open-drawer",
				//PC端:下方拓展弹窗(主页)
				".recommend-box",
				//PC端:登录弹窗(右上角)
				".login-popover",
				//PC端:登录弹窗(右下角)
				".bottom-login-guide",
			],
			overflow: true,
		},
		{
			name: "知乎发现页",
			url: "www.zhihu.com/explore",
			items: [
				//PC端:登录按钮(发现页)
				".ExploreHomePage-specialsLogin",
			],
			fun: function () {
				//发现页:热点和问题高度保持一致;
				if (location.href.includes("www.zhihu.com/explore")) {
					addStyle(".ExploreHomePage-square > div:nth-child(3){margin: 0px}");
				}
			},
		},
		{
			name: "知乎",
			url: "zhihu.com",
			items: [
				//悬浮按钮:是否在知乎app内阅读全文
				".MobileModal-wrapper",
				//悬浮按钮:打开知乎(主页),打开
				".OpenInAppButton",
			],
			overflow: true,
			fun: function () {
				//PC端拦截登录弹窗
				if (!/Mobile|Android|iPhone/i.test(navigator.userAgent)) {
					window.addEventListener("DOMContentLoaded", function () {
						let loginBtn = document.querySelector(".css-1rwz7is");
						//检验是否登录
						if (loginBtn) {
							//执行监听
							let observer = new MutationObserver(removeLoginNotice);
							observer.observe(document, { childList: true, subtree: true });

							onload = function () {
								loginBtn.addEventListener("click", function () {
									LoginFlag = false;
								});
							};
						}
					});
					/**
					 * 删除登录弹窗
					 *
					 * @param      {MutationRecord[]}  mutationsList  The mutations list
					 * @param      {MutationObserver}  observer       The observer
					 */
					function removeLoginNotice(mutationsList) {
						for (let mutation of mutationsList) {
							for (let node of mutation.addedNodes) {
								//有登陆弹窗1时:模拟点击关闭按钮
								if (node.querySelector(".signFlowModal")) {
									let button = node.querySelector(".Button.Modal-closeButton.Button--plain");
									if (button) {
										if (LoginFlag == true) {
											button.click();
										} else {
											LoginFlag = true;
										}
										return;
									}
								}
								//拦截登录弹窗2
								if (getXpath('//button[text()="立即登录/注册"]', node)) {
									getXpath('//button[text()="立即登录/注册"]', node).parentElement.parentElement.remove();
								}
							}
						}
					}
				}
			},
		},
		{
			name: "百度",
			url: "baidu.com",
			items: [
				//悬浮按钮:打开百度
				"#J-invoke-baiduApp-float",
			],
		},
		{
			name: "百度贴吧",
			url: "tieba.baidu.com",
			items: [
				//悬浮按钮:打开百度贴吧
				".nav-bar-bottom",
			],
		},
		{
			name: "百度文库1",
			url: "/wk.baidu.com/view/",
			items: [
				//悬浮按钮(上方):百度文库
				".wk-student-defense",
			],
		},
		{
			name: "百度文库2",
			url: "tanbi.baidu.com/h5apptopic/browse/",
			items: [
				//悬浮按钮(上方):百度文库
				".wk-student-limit-jump",
				".bartop",
				//悬浮按钮(下方):下载App,继续阅读
				".wk-bottom-btn",
			],
		},
		{
			name: "百家号",
			url: "baijiahao.baidu.com/s",
			items: [
				//悬浮按钮:百度APP内打开
				"#bdrainrwDragButton",
			],
		},
		{
			name: "百度资讯+百度首页",
			url: "mbd.baidu.com/newspage/data",
			items: [
				//悬浮按钮:百度APP内打开
				"#bdrainrwDragButton",
				//悬浮按钮:百度APP内播放
				".drag-bottom",
			],
		},
		{
			name: "腾讯新闻1",
			url: "view.inews.qq.com/",
			items: [
				//固定按钮:打开
				".slider-top-bar_sliderWrapper__1Nize",
				//悬浮按钮:打开腾讯新闻,看更多热点资讯
				".bottom-bar_buttonWrap__NXBe-",
			],
		},
		{
			name: "腾讯新闻2",
			url: "xw.qq.com/",
			items: [
				//固定按钮:打开(首页)
				"#opeApp",
			],
		},
		{
			name: "腾讯视频",
			url: "m.v.qq.com",
			items: [
				//下载弹窗
				".at-app-banner",
				//打开APP查看高清内容
				".open_app_bottom",
			],
		},
		{
			name: "优酷视频",
			url: "youku.com",
			items: [
				//下载弹窗
				".callEnd_box",
				//悬浮按钮(主页):打开优酷APP更流畅
				".callEnd_fixed_box",
				//悬浮按钮:打开优酷APP更流畅
				".undefined",
				//悬浮按钮:红包
				".Corner-container",
			],
		},
		{
			name: "爱奇艺",
			url: "iqiyi.com/",
			items: [
				//下载弹窗
				".m-iqyGuide-layer",
				//打开爱奇艺APP,看精彩视频
				"[class^=ChannelHomeBanner]",
				//PC端:登录提示上侧
				".pl__1",
			],
		},
		{
			name: "好看视频",
			url: "haokan.baidu.com/",
			items: [
				//悬浮按钮:打开好看app(中间)
				".open-app-top",
				//固定文字:打开APP(多)
				".top-video-card-img-app",
				//固定按钮:下载APP(视频播放时)
				".video-player-download-tips",
				//固定按钮:打开(底部)
				".open-app-bottom",
				//固定按钮:打开(底部:个别)
				".NewOpenApp",
				//PC端固定按钮:下载APP(视频暂停时)
				".player-lefttip-inner",
				//PC端登录提示:登录提示
				"#passport-login-pop",
				//PC端登录提示:朦胧背板
				".pop-mask",
				//PC端登录提示:悬浮提示
				".page-top-rightinfo-popover",
			],
		},
		{
			name: "m1905电影网",
			url: "1905.com/",
			items: [
				//悬浮弹窗:打开app
				"#popupModule",
				//悬浮按钮:
				".open-link",
			],
		},
		{
			name: "百度搜索",
			url: "baidu.com",
			items: [
				//搜索结果:小程序
				"[srcid=xcx_multi]",
				//搜索结果:百度手机助手
				"[srcid=app_mobile_simple]",
				//搜索结果:百度手机助手:安全下载
				"[srcid=app_mobile_simple_safety]",
				//搜索结果:百度应用搜索(IOS)
				"[srcid=app_mobile_ios]",
			],
		},
		{
			name: "哔哩哔哩",
			url: "bilibili.com",
			items: [
				//悬浮按钮:打开app,看你感兴趣的内容(主页)
				".m-home-float-openapp",
				//悬浮按钮:打开app(UP主页)
				".m-space-float-openapp",
				//悬浮按钮:打开app,看高清内容(视频全屏)
				".mplayer-widescreen-callapp",
				//悬浮按钮:bilibili内打开(底部)
				".m-float-openapp",
				//悬浮弹窗:bilibili内打开
				".openapp-dialog",
				//固定按钮：播放时下载
				".mplayer-widescreen-callapp",
				//PC端:登录提示(右下角)
				".lt-row",
				//PC端:登录提示(右上角)
				".login-panel-popover:has(.login-tip-content)",
				//PC端:登录提示(播放器)
				".bpx-player-toast-wrap",
				//PC端:登录提示(右上角)
				"div:has(.unlogin-popover-avatar)",
				//PC端:滑动提示(正下方:首次)
				".trial-feed-wrap",
			],
			fun: function () {
				let add;
				function mutationCallback(record, observer) {
					//已确定登录:停止监听
					let login = document.querySelector(".header-entry-mini");
					if (login) {
						observer.disconnect();
					}
					//已确定未登录:执行函数
					let loginBtn = document.querySelector(".header-login-entry");
					if (loginBtn) {
						if (!add) {
							console.log("脚本注入成功");
							//添加事件:不拦截
							loginBtn.addEventListener("click", function () {
								LoginFlag = false;
							});
							add = true;
						}
						for (let arr of record) {
							for (let node of arr.addedNodes) {
								let button;
								try {
									button = node.querySelector(".bili-mini-close-icon");
								} catch (error) {
									/* empty */
								}
								if (button) {
									//有登陆弹窗时:模拟点击关闭按钮
									if (LoginFlag == true) {
										console.log(LoginFlag);
										console.log("自动拦截");
										button.click();

										console.log("恢复播放");
										let video = document.querySelector(".bpx-player-video-wrap video");
										video.play();
									} else {
										console.log(LoginFlag);
										console.log("手动拦截");
										LoginFlag = true;
									}
									return;
								}
							}
						}
					}
				}
				let observer = new MutationObserver(mutationCallback);
				observer.observe(document, { childList: true, subtree: true });
			},
		},
		{
			name: "B站专栏",
			url: "bilibili.com/read/",
			items: [
				//悬浮按钮:打开app
				"#app>div>bili-open-app.float-btn",
				//PC端:登录提示
				"div:has(.unlogin-popover-avatar)",
			],
		},
		{
			name: "B站笔记",
			url: "bilibili.com/opus/",
			items: [
				//悬浮按钮:打开App,看更多精彩内容
				".float-btn",
				//悬浮弹窗:打开APP
				".openapp-dialog",
				//PC端:登录提示
				"div:has(.unlogin-popover-avatar)",
			],
		},
		{
			name: "西瓜视频",
			url: "ixigua.com",
			items: [
				//打开弹窗:打开
				".landing_guide",
				//PC端:登录提示
				".loginBenefitNotification",
				//悬浮按钮:打开西瓜视频,看全网超清视频
				".xigua-download",
			],
		},
		{
			name: "抖音电脑版",
			url: "www.douyin.com",
			items: [
				//PC端:下载电脑客户端
				"#douyin-web-download-guide-container",
				//PC端:右下角登录提示(画质)
				".login-clarity-new",
				//PC端:登陆后查看评论
				"#related-video-card-login-guide",
				//PC端:底部登录提示
				".wwNZW6za",
			],
			fun: function () {
				//登陆后查看评论模糊
				addStyle("._61cgy6j3{filter: none !important}");
				//拦截登录弹窗
				onload = function () {
					//增加点击事件
					let inter = setInterval(() => {
						let loginBtn = getXpath('//div[text()="登录"] | //p[text()="登录"]', document).parentElement;
						if (loginBtn) {
							loginBtn.addEventListener("click", function () {
								LoginFlag = false;
							});
							clearInterval(inter);
						}
					}, 1000);
				};

				/**
				 * Removes a login notice.
				 *
				 * @param      {MutationRecord[]}  mutationsList  The mutations list
				 * @param      {MutationObserver}  observer       The observer
				 */
				let removeLoginNotice = function (mutationsList) {
					for (let mutation of mutationsList) {
						for (let node of mutation.addedNodes) {
							if (node.nodeType == Node.ELEMENT_NODE) {
								let closeBtn = node.querySelector(".dy-account-close");
								//关闭登录弹窗
								if (closeBtn) {
									if (LoginFlag == true) {
										closeBtn.click();
									} else {
										LoginFlag = true;
									}
								}
								return;
							}
						}
					}
				};
				//执行监听
				let observer = new MutationObserver(removeLoginNotice);
				observer.observe(document, { childList: true, subtree: true });
			},
		},
		{
			name: "丁香园",
			url: "3g.dxy.cn",
			items: [
				//悬浮按钮:APP内打开
				"[class^=fixedBtn]",
				//悬浮按钮:App内打开(主页)
				".wrap",
			],
		},
		{
			name: "健康界",
			url: "www.cn-healthcare.com/",
			items: [
				//悬浮按钮:打开(底部滚动)
				"footer",
			],
		},
		{
			name: "微博",
			url: "m.weibo.cn",
			items: [
				//悬浮按钮:在微博内打开(百度热议)
				".app-btn-box",
				//悬浮按钮:登录/注册
				".login-btn",
				//小程序
				".wrap",
			],
		},
		{
			name: "新浪新闻",
			url: "sina.cn/",
			items: [
				//悬浮按钮:打开APP
				".callApp_fl_btn",
			],
		},
		{
			name: "新浪财经",
			url: "sina.cn/",
			items: [
				//悬浮弹窗:立即更新(主页:首次访问)
				"#SFA_newVersion_pop",
				//悬浮按钮:打开App中查看(主页:底部)
				".m-client-call2",
				//固定按钮:立即登录(主页:资讯)
				".login-box",
				//悬浮按钮:立即查看(资讯:底部,首次访问)
				".wap-msg-bar-wap",
				//悬浮按钮:去APP听语音播报(资讯:中间)
				".broadcast",
				//悬浮按钮:打开APP(资讯:顶部,有bug)
				".m-sentiment-blk",
				//悬浮按钮:打开APP(资讯:底部)
				".m-guss-caijing",
				//固定按钮:立即体验(资讯:底部)
				"#norm_qrcode_link_auto",
				//悬浮按钮:打开APP(子栏1:底部)
				"#subPage_bottom_callup_btn",
				//悬浮按钮:打开APP(子栏2:底部)
				"#__callup_bottom_new",
				//悬浮按钮:打开APP(子栏2:顶部,有bug)
				".js-app-header",
			],
			fun: function () {
				//修复上述规则产生的bug
				let inter = setInterval(() => {
					let item = document.querySelector(".compatibility-mode");
					if (item.style.marginTop == "0px") {
						clearInterval(inter);
					} else {
						item.style.marginTop = "0px";
					}
				}, 1000);
			},
		},
		{
			name: "东方财富网",
			url: "wap.eastmoney.com/",
			items: [
				//悬浮按钮:打开APP(顶部)
				".fixed_top",
				//固定按钮:下载(主页:顶部)
				"#IndexDT",
				//悬浮按钮:打开下载(主页:顶部)
				".emwapas_xldt_fixed",
				//悬浮按钮:打开APP(主页:底部)
				".open-inapp",
			],
		},
		{
			name: "东方财富网:股吧",
			url: "mguba.eastmoney.com/",
			items: [
				//悬浮弹窗:打开APP
				"#appbox",
				//悬浮按钮:东方财富APP内打开(底部)
				"#open_app",
			],
		},
		{
			name: "电子发烧友",
			url: "m.elecfans.com",
			items: [
				//悬浮按钮:主页右侧
				".hm_quick",
				//悬浮按钮:登陆/注册
				".login-reg-fixed",
				//悬浮按钮:上方打开app
				".open_app",
			],
		},
		{
			name: "人民网",
			url: "app.people.cn",
			items: [
				//悬浮按钮:打开(底部)
				".app-bot-wrap",
			],
		},
		{
			name: "新京报",
			url: "m.bjnews.com.cn/detail/",
			items: [
				//悬浮按钮:立即打开(顶部)
				".xjb-top",
			],
		},
		{
			name: "观察者网",
			url: "guancha.cn",
			items: [
				//固定按钮:点击下载(顶部)
				".g_header44",
				//悬浮按钮:APP专享(底部)
				".g_swiper_container",
			],
		},
		{
			name: "澎湃新闻",
			url: "m.thepaper.cn/newsDetail_forward",
			items: [
				//悬浮按钮:新闻滚条(底部)
				"[class^=index_footer_banner]",
				"[.index_footer_banner__Mcr_R]",
			],
		},
		{
			name: "凤凰新闻",
			url: "ifeng.com",
			items: [
				//悬浮按钮:立即打开(主页)
				"[class^=index_fixSlide_]",
				//悬浮按钮:滚动新闻(新闻底部)
				"[class^=index_bottom_box_]",
				//悬浮按钮:立即打开(财经底部)
				"[class^=index_bottomSlide_]",
				//悬浮按钮:滚动新闻(卫视底部)
				"[class^=index_fixBottom_]",
			],
		},
		{
			name: "网易新闻",
			url: "3g.163.com",
			items: [
				//固定按钮：App内打开(底部)
				".backflow-floating",
			],
		},
		{
			name: "网易新闻",
			url: "m.163.com",
			items: [
				//固定按钮：App内打开(底部)
				".backflow-floating",
			],
		},
		{
			name: "搜狐",
			url: "m.sohu.com/a/",
			items: [
				//悬浮按钮:打开APP
				"#CallAppContainer",
				".CallAppContainer",
			],
		},
		{
			name: "今日头条:移动端",
			url: "m.toutiao.com/",
			items: [
				//悬浮按钮：App内打开(底部)
				".m-bottom-container",
				//悬浮按钮:去首页(文章)
				".m-index-tag"
			],
		},
		{
			name: "今日头条:PC端",
			url: "www.toutiao.com/",
			items: [
				//悬浮弹窗:添加今日头条到电脑桌面
				".add-panel",
				//悬浮弹窗:扫码下载今日头条
				"download-panel"
			],
		},
		{
			name: "东方资讯",
			url: "mini.eastday.com/nsa/",
			items: [
				//PC端:悬浮弹窗:添加到桌面
				"#dftt-message-wrapper",
			],
		},
		{
			name: "虎嗅",
			url: "m.huxiu.com",
			items: [
				//悬浮按钮:go!(主页)
				".guide-wrap",
				//悬浮按钮:打开(顶部)
				".js-top-fixed",
				//悬浮按钮:打开(底部)
				".bottom-open-app-btn",
			],
		},
		{
			name: "虎扑",
			url: "m.hupu.com",
			items: [
				//悬浮按钮:App内打开
				".open-hupu",
			],
		},
		{
			name: "豆瓣",
			url: "m.douban.com",
			items: [
				//固定按钮:用App打开(电影详情页)
				".subject-banner",
				//悬浮按钮:豆瓣APP内打开
				".talion-nav-footer",
			],
		},
		{
			name: "太平洋电脑",
			url: "g.pconline.com.cn",
			items: [
				//悬浮按钮:打开app(底部)
				".btnForAppOpenImg",
				//悬浮按钮:打开知科技App
				".btnForAppOpenA",
				//固定按钮:立即打开(底部)
				".WakeUptop",
				//悬浮按钮:打开(底部)
				".page-float-box",
			],
		},
		{
			name: "中关村在线",
			url: "m.zol.com.cn",
			items: [
				//悬浮按钮:打开APP
				".cover-back_s",
				//悬浮按钮:APP内打开
				"#bottom-fixed-wrapper > span",
			],
		},
		{
			name: "中关村在线2(报价+论坛)",
			url: "wap.zol.com.cn",
			items: [
				//悬浮按钮:打开APP
				".cover-back_s",
				//悬浮按钮:APP内打开
				"#bottom-fixed-wrapper > span",
			],
		},
		{
			name: "汽车之家PC版",
			url: "www.autohome.com.cn",
			items: [
				//悬浮按钮:登录提示(PC端)
				"#loginGuide",
			],
		},
		{
			name: "汽车之家移动版",
			url: "m.autohome.com.cn",
			items: [
				//悬浮按钮: App内打开
				"#float_new_button",
			],
		},
		{
			name: "太平洋汽车",
			url: "m.pcauto.com.cn/",
			items: [
				//悬浮弹窗: App内打开
				"#home-bottom-half-dialog",
				//悬浮按钮: 轮播评论
				"#dmListOuter",
			],
		},
		{
			//www.taptap.com
			name: "taptap",
			url: "www.taptap.cn",
			items: [
				//悬浮按钮:打开taptap
				".open-app-global-float",
			],
		},
		{
			//m.taptap.com
			name: "taptap",
			url: "m.taptap.cn",
			items: [
				//悬浮按钮:打开taptap查看更多精彩内容
				".app-download__wrapper",
				//苹果端:悬浮按钮:添加到桌面
				".show-add-to-screen",
				//苹果端:固定按钮:添加到桌面
				".add-to-screen-wrap",
			],
		},
		{
			//https://m.ithome.com/
			name: "it之家",
			url: "m.ithome.com",
			items: [
				//固定按钮(底部):立即打开
				".open-app-banner",
			],
		},
		{
			name: "360docPC版",
			url: "www.360doc.com/content/",
			items: [
				//登录弹窗
				"iframe",
				//登录弹窗:朦胧模板
				"iframe~div",
			],
		},
		{
			name: "开源中国",
			url: "www.oschina.net",
			items: [
				//悬浮按钮(底部):立即打开
				".app-download-banner-box",
			],
		},
		{
			name: "segmentfault思否",
			url: "segmentfault.com/q",
			items: [
				//登录弹窗
				".modal-dialog-centered",
			],
		},
		{
			name: "阿里云开发者社区",
			url: "developer.aliyun.com/article/",
			items: [
				//阿里云App内打开
				".app-fixed-btn",
			],
		},
		{
			name: "华为云开发者社区",
			url: "huaweicloud.csdn.net/",
			items: [
				//加入社区
				".user-desc-fix",
			],
		},
		{
			//https://m.36kr.com/p/1964588951470856
			name: "36氪",
			url: "m.36kr.com/p/",
			items: [
				//悬浮按钮(顶部):打开
				".article-top-swiper-goapp",
			],
		},
		{
			name: "雪球",
			url: "xueqiu.com/",
			items: [
				//悬浮按钮:加群学习(主页)
				".FloatDownloadButton_mobile_xiaoxue-button_1jZ",
				//悬浮按钮:加群学习(文章)
				".index_xiaoxue-button_1Av",
				//悬浮按钮:登录提示
				".widget__download-app"
			],
			fun: function () {
				//悬浮按钮:打开app(话题)
				document.onreadystatechange = function () {
					if (document.readyState === "complete") {
						document.querySelector("[class^=FloatDownloadButton_mobile_openapp__fix_]").remove();
					}
				};

				/**
				 * Removes a login notice.
				 *
				 * @param      {MutationRecord[]}  mutationsList  The mutations list
				 * @param      {MutationObserver}  observer       The observer
				 */
				let removeLoginNotice = function (mutationsList) {
					for (let mutation of mutationsList) {
						for (let node of mutation.addedNodes) {
							let closeBtn = document.querySelector(".modal__login .close");
							//关闭登录弹窗
							if (LoginFlag == true) {
								closeBtn.click();
							} else {
								LoginFlag == true;
							}
							return;
						}
					}
				};
				//拦截登录弹窗
				document.addEventListener("DOMContentLoaded", function () {
					let loginBtn = document.querySelector(".loginBtn");
					//检验是否登录
					if (loginBtn.textContent === "登录") {
						//增加点击事件
						loginBtn.addEventListener("click", function () {
							LoginFlag = false;
							//未知bug:导致第一次点击无法生效,所以这里再点击一次
							loginBtn.click();
						});
					}
					//执行监听
					let observer = new MutationObserver(removeLoginNotice);
					observer.observe(document, { childList: true, subtree: true });
				});
			},
		},
		{
			name: "天眼查",
			url: "m.tianyancha.com/",
			items: [
				//悬浮按钮:打开app(主页)
				".swiper-container",
				//悬浮按钮:下载APP(企业)
				"#banner_mobile_v2",
			],
		},
		{
			name: "站酷移动版",
			url: "m.zcool.com.cn/",
			items: [
				//悬浮按钮:打开app(主页)
				".bottom-App",
				//悬浮按钮:打开app
				"[class^=wapHeader_footer-button]",
			],
		},
		{
			name: "站酷PC版",
			url: "www.zcool.com.cn/",
			items: [
				//登录按钮
				".sideUnlogin",
				//登录弹窗
				".ReactModal__Overlay--after-open:not(.ReactModal__Overlay_content-page)",
			],
			fun: function () {
				//登录弹窗导致的页面无法滑动
				addStyle("html,body {overscroll-behavior: unset !important;overflow: unset !important;}");
			},
		},
		{
			name: "小红书",
			url: "www.xiaohongshu.com",
			items: [
				//App内打开(视频)
				".bottom-button-box",
				//App内打开(笔记)
				".bottom-bar",
			],
			fun: function () {
				let mo = new MutationObserver(function (mutations) {
					for (let mutation of mutations) {
						for (let node of mutation.addedNodes) {
							let button = node.querySelector(".icon-btn-wrapper");
							if (button) {
								if (LoginFlag) {
									button.click();
								} else {
									LoginFlag = true;
								}
								return;
							}
						}
					}
				});
				let loginBtn = document.querySelector(".login-btn");
				if (loginBtn) {
					loginBtn.addEventListener(
						"click",
						function () {
							LoginFlag = false;
						},
						true,
					);
					mo.observe(document, { childList: true, subtree: true });
				}
			},
		},
		{
			name: "喜马拉雅",
			url: "m.ximalaya.com/",
			items: [
				//悬浮按钮:打开APP,完整收听1
				".album-btn-container",
				//悬浮按钮:打开APP,完整收听2
				".btn-open",
				//打开APP2
				".downloadButton",
			],
		},
		{
			//https://wap.cnki.net/touch/web/Journal/Article/WLAQ202302061.html
			name: "中国知网",
			url: "wap.cnki.net/",
			items: [
				//App内打开
				".Appopen",
				//滚动新闻
				"#fix-bottom",
			],
		},
		{
			name: "zfrontier",
			url: "www.zfrontier.com",
			items: [
				//App内打开
				".app-opener",
			],
		},
		{
			name: "必应搜索",
			url: "bing.com",
			items: [
				//必应中打开(Chrome中专属)
				".bnp_rich_div_visible",
			],
		},
		{
			name: "w3cschool",
			url: "www.w3cschool.cn/",
			items: [],
			fun: function () {
				//复制文件时的弹窗
				onload = function () {
					let mo = new MutationObserver(function (mutations) {
						for (let mutation of mutations) {
							for (let node of mutation.addedNodes) {
								if (node.nodeName == "DIV" && node.className == "") {
									node.style.display = "none";
								}
							}
						}
					});
					mo.observe(document, { childList: true, subtree: true });
				};
			},
		},
		{
			name: "什么值得买",
			url: "m.smzdm.com/",
			items: [
				//app内打开
				".footer-banner-wrap",
				//国内好价:qpp内打开
				".wrapper",
				".foot-banner",
			],
		},
	];

	/**
	 * 主体部分
	 */
	for (let website of websites) {
		if (location.href.indexOf(website.url) != -1) {
			//隐藏/拦截骚扰元素
			if (website.items) {
				for (let item of website.items) {
					addStyle(item + "{display: none !important}");
				}
			}
			//修复移动版页面不允许滑动
			if (website.overflow) {
				addStyle("body{overflow: auto !important}");
			}
			//执行额外方案
			if (website.fun) {
				website.fun();
			}
		}
	}

	//默认监听
	let LoginFlag = true;
	//默认添加
	let ClickFlag = true;

	/**
	 * 通过内容(xpath)获取节点
	 *
	 * @param      {string}  xpath   内容
	 * @param      {Node}  parent  父元素
	 * @return     {Node}  元素
	 */
	function getXpath(xpath, parent) {
		let xpathResult = document.evaluate(xpath, parent || document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
		return xpathResult.singleNodeValue;
	}

	/**
	 * 向head标签内添加样式
	 *
	 * @param      {string}  text    CSS样式
	 */
	function addStyle(text) {
		let css = document.createElement("style");
		css.innerText += text;
		document.head.append(css);
	}
})();
