我正在为 Chrome 扩展程序编写脚本,它的作用是拆分 GPT 广告请求 URL 并将字符串插入表中。
以下是请求 URL 的示例:
https://securepubads.g.doubleclick.net/gampad/ads?gdfp_req=1&pvsid=933914290088983&correlator=2431396676467655&output=ldjh&impl=fifs&eid=21062833%2C21065233%2C21065310&vrg=2019121002&guci=2.2.0.0.2.2.0.0&sc=1&sfv=1-0-37&ecs=20200103&iu_parts=114240681%2Cipropertymy%2Crent%2Cpropertydetails&enc_prev_ius=0%2F1%2F2%2F3&prev_iu_szs=1x1&ists=1&prev_scp=location1%3Dselangor%26location2%3Dcyberjaya%26location3%3Dhyve%26propertytype%3Dserviced-residence%26bedroom%3DStudio%26size%3D500-1000%26rentprice%3D800-1K%26position%3Dinterstitial%26lang%3Den-GB&cust_params=district%3D%26...
我一直在浏览其他人准备的脚本,我想知道如何选择可以在表格中显示的字符串值。如果包含其他定位参数,请求 URL 可能会变得很长。
这是示例脚本,
var consoles = document.getElementById("customers"),
headers = [],
table_rows = 0;
chrome.devtools.network.onRequestFinished.addListener(function(e) {
if (e.request.url.indexOf("securepubads.g.doubleclick.net/gampad/ads") >= 0) {
var n = e.request.url.split("&");
(table_rows += 1),
n.forEach(function(e, n) {
"https:" == e.split("=")[0]
? s("Protocol", e.split("=")[0])
: "" == e.split("=")[0] ||
s(e.split("=")[0], unescape(e.split("=")[1]));
});
}
function s(e, n) {
var s = document.getElementsByTagName("table")[0];
if (1 == headers.includes(e)) {
headers.findIndex(function(n) {
return n === e;
}),
s.rows.length != table_rows + 1 && s.insertRow();
var r = table_rows;
if (s.rows[r].cells.length != t)
for (var l = 0; l == t; l++) s.rows[r - 1].insertCell().innerHTML = "-";
(s.rows[r].insertCell().innerHTML = n),
"prev_scp" == e &&
(s.rows[r].lastElementChild.innerText = decodeURIComponent(
decodeURI(n.replace(/&/g, "\n"))
));
} else {
headers.push(e),
0 == s.rows.length && s.insertRow(),
(s.rows[0].insertCell().innerHTML = e);
var t = s.rows[0].cells.length;
1 == s.rows.length && s.insertRow();
r = table_rows;
if (s.rows[0].cells.length != t)
for (l = s.rows[0].cells.length; l <= t; l++)
(s.rows[0].insertCell().innerHTML = n || "-"), (n = null);
else
(s.rows[r].insertCell().innerHTML = n),
"url" == e &&
(s.rows[r].lastElementChild.innerText = decodeURIComponent(
decodeURI(n.replace(/&/g, "\n"))
));
}
}
}),
document.getElementById("reload").addEventListener("click", function() {
window.location.href = window.location.href;
});
当前脚本生成这种表,
pvsid = 123456
jar = 2020-1-6-10
eid = 21065332,21062889
correlator = 123456
output = 10
iu_parts = abcd,12,xyz
prev_scp = position: abovefold
cust_params = lang=en-GB
我希望能够只显示这些选定的参数,
pvsid = 12345
correlator = 123456
prev_scp = position: abovefold
cust_params = lang=eng-GB
关于我可以使用哪种方法从拆分 URL 中选择要显示的参数然后将其放入表中的任何想法?