// ==UserScript== // @name 邦德提取网页广告链接并发送ajax // @namespace http://tampermonkey.net/ // @version 0.1 // @description 提取网页(如色情)广告链接 // @author 木木 // @match htt*://*/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... console.log(0.1); window.onload=function(){ show_adhref(); } function show_adhref() { console.log(111, $("img:not([title])").parents("a")); //当前域名 var alist = $("img:not([title])").parents("a:not([title])"); console.log(333, alist); var ahref = []; var ahref_samedomain = []; var r1 = /.*?(gif|png|jpg)/gi; var r2 = new RegExp("javascript|mailto:|#|mqq:|sinaweibo:|alipays:|weixin:|sms:|baidu.com|" + location.host ,"gi"); var r3 = new RegExp(location.host ,"gi"); for (var index in alist) { if (alist[index].href && !alist[index].href.match(r1) && !alist[index].href.match(r2)) { ahref.push(alist[index].href); } if (alist[index].href && alist[index].href.match(r3)) { ahref_samedomain.push(alist[index].href); } } ahref = unique(ahref); ahref_samedomain = unique(ahref_samedomain); console.log(222,ahref); console.log(555,ahref_samedomain); var ahref_content = ahref.join("\r\n"); var ahref_samedomain_content = ahref_samedomain.join("\r\n"); var ahref_samedomain_a_str = ''; for (var index2 in ahref_samedomain) { var current_ahref = ahref_samedomain[index2]; ahref_samedomain_a_str += `

${current_ahref}

`; } //向后台发送ajax if (ahref.join(",")) { $.post('http://192.168.200.154:10015/api/record_adhref',{ahref:ahref.join(","), domain:location.host},function(res){ console.log(777,res) },'json') } if (ahref_content !== '') { $("body").append(`
同域名:\r\n${ahref_samedomain_a_str}
`); } } function unique(arr) { if (!Array.isArray(arr)) { console.log('type error!') return } var array = []; for (var i = 0; i < arr.length; i++) { if (array .indexOf(arr[i]) === -1) { array .push(arr[i]) } } return array; } unsafeWindow.multi_open_youhou = function multi_open_youhou() { var alist = $("img:not([title])").parents("a:not([title])"); console.log(666, alist); for (var index in alist) { if (alist[index].href) { window.open(alist[index].href); } } } })();