使用Google chrome扩展程序重定向网址

时间:2018-11-11 18:29:47

标签: google-chrome google-chrome-extension

这是我第一次使用javascript和chrome扩展程序。我想在法定网址的末尾附加?share=1,所以我不必注册。我尝试查看了一些答案,但无法找到为什么在URL末尾将此字符串附加两次?share=1?shared=1

这是我的代码

Manifest.json

{
"manifest_version": 2,
"name": "Quora view",
"description": "View quora without signing up ",
"version": "1.0.0",
"icons": {"128": "icon128.png"},
"background": {"scripts":["background.js"]},
"permissions": [
    "activeTab",
    "webRequest",
    "*://www.quora.com/*",
    "webRequestBlocking"
]}

background.js

let host = "https://www.quora.com";
let post = "?share=1";
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
     return {redirectUrl: host + details.url.match(/^https?:\/\/[^\/]+[\S\s]*)/)[1] + post};
},
{
    urls: [
        "*://www.quora.com/*",
    ]
},
["blocking"]
);

0 个答案:

没有答案