相关疑难解决方法(0)

按名称获取cookie

我有一个getter来从cookie中获取值.

现在我有两个名字shares=和名字的饼干obligations=.

我想让这个getter只是为了从义务cookie中获取值.

我该怎么做呢?因此,for将数据拆分为单独的值并将其放入数组中.

 function getCookie1() {
    // What do I have to add here to look only in the "obligations=" cookie? 
    // Because now it searches all the cookies.

    var elements = document.cookie.split('=');
    var obligations= elements[1].split('%');
    for (var i = 0; i < obligations.length - 1; i++) {
        var tmp = obligations[i].split('$');
        addProduct1(tmp[0], tmp[1], tmp[2], tmp[3]);
    }
 }
Run Code Online (Sandbox Code Playgroud)

javascript cookies

337
推荐指数
22
解决办法
59万
查看次数

Chrome 扩展程序将具有动态值的脚本注入到具有严格 CSP 的页面中

我正在创建一个隐私扩展,该扩展在 document_start 上运行内容脚本。

内容脚本需要为每个不同的来源注入一个具有动态值的脚本,例如 google.com、twitter.com 等。

这是我的内容脚本:

console.log("Content Script Running ...");
console.log("Window origin: " + window.location.href);

function inject(filePath) {
  var script = document.createElement('script');
  script.src = chrome.extension.getURL(filePath);
  script.onload = function() {
    this.remove();
  };
  (document.head || document.documentElement).appendChild(script);
}

function injectText(text) {
  var script = document.createElement('script');
  script.textContent = text;
  script.onload = function() {
    this.remove();
  };
  (document.head || document.documentElement).appendChild(script);
}

function getSeed(origin) {
    // Get a Storage object
    var storage = window.sessionStorage;

    // Do we already have a seed in storage for this origin …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension content-security-policy

4
推荐指数
1
解决办法
1454
查看次数

谷歌chrome扩展:如何在页面重新加载后立即注入脚本?

我有一个后台脚本,定期重新加载当前选项卡.

var code = 'window.location.reload();';
chrome.tabs.executeScript(my_active_tab, {code: code});
Run Code Online (Sandbox Code Playgroud)

每次重新加载页面后,我立即要注入另一个脚本.

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab){
    if (changeInfo.status == 'complete') {
        chrome.tabs.executeScript(tabId, { file: "my_script.js" });
    }
});
Run Code Online (Sandbox Code Playgroud)

以上是我目前的代码.问题是,它工作但速度太慢,因为它在每个图像加载后都会等待.

我的目标是在DOM加载后立即执行脚本.有任何想法吗?

javascript google-chrome background-process google-chrome-extension

1
推荐指数
1
解决办法
1950
查看次数