0

Firefox 有一个名为 tumblr 侧边栏的扩展,我正在尝试将其修改为每 X 秒自动刷新一次,但尽管尝试了我发现的大多数方法,但我无法弄清楚。

该扩展包含一些核心文件,首先index.html

<!doctype html>
<html>
<head>
    <meta http-equiv="refresh" content="0; url=https://www.tumblr.com/">

</head>
<body>
    <h1>Loading...</h1>
</body>
</html>

当然,我尝试修改已经定义的刷新间隔,但由于某种原因这不起作用。

background.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
  <body>
    <script id="sideapp" src="sideapp.js"></script>
    <script src="js.js"></script>
    <link href="css.css"/>
  
</body>
</html>

我尝试向此文件添加自动刷新无济于事。

js.js

// Will display none the ads div by class name
function update_ui(){
    var elementList = document.querySelectorAll("li.standalone-ad-container");
    for(i=0; i<elementList.length; i++) {
        elementList[i].style.display =    'none';
    }
}
// Will do it on scrolling event
window.addEventListener('scroll', function (evt) {
    update_ui();
});

// -- MY CODE -- setTimeout(function() { window.location=window.location;},5000);

// Do it on load
update_ui();

如您所见,我尝试更改 js 文件以刷新,但这也不起作用。

然后是sidebar.js

var app = {}, tabId;

app.storage = (function () {
  var objs = {};
  window.setTimeout(function () {
    chrome.storage.local.get(null, function (o) {
      objs = o;
      document.getElementById("sideapp").src = "sideapp.js";
    });
  }, 300);
  /*  */
  return {
    "read": function (id) {return objs[id]},
    "write": function (id, data) {
      var tmp = {};
      objs[id] = data;
      tmp[id] = data;
      chrome.storage.local.set(tmp, function () {});
    }
  }
})();

var winid;

chrome.browserAction.onClicked.addListener(function () {
  chrome.windows.getCurrent(function (win) {
    if (winid) chrome.windows.update(winid, {"focused": true});
    else {
      var width = config.UI.size.width;
      var height = config.UI.size.height;
      var url = "https://www.tumblr.com/";
      var top = win.top + Math.round((win.height - height) / 2);
      var left = win.left + Math.round((win.width - width) / 2);
      chrome.windows.create({'url': url, 'type': 'popup', 'width': width, 'height': height, 'top': top, 'left': left}, function (e) {winid = e.id});
    }
  });
});

chrome.windows.onRemoved.addListener(function (e) {if (e === winid) winid = ''});

var config = {};

config.UI = {
  set size (o) {if (o) app.storage.write("size", o)},
  get size () {
    var _size = app.storage.read("size");
    if (_size) return _size;
    else {
      var tmp = {"width": 1000, "height": 750};
      config.UI.size = tmp;
      return tmp;
    }
  }
};

我还尝试在此文件中添加刷新功能,但我不确定这是否有效,因为我不熟悉 Firefox 侧边栏。

任何帮助将不胜感激。

4

0 回答 0