我想让用户决定何时运行脚本,以便在浏览器打开时显示"off"图标并且没有脚本运行; 但是当用户点击它时,它会变为"on"图标并执行用户脚本,直到用户点击为止.我有两个png图标,每个32x32:on.png和off.png.
我的两个问题:
如何将默认图标设置为my off.png?我尝试了这个,manifest.json但它没有设置图标,而是显示了一个拼图(我假设默认):
...
"browser_action": {
"default_icon": {
"32": "off.png"
},
"default_title": "icon"
},
"icons": {
"32": "on.png",
"32": "off.png"
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [{
"js": ["SCRIPT.user.js"]
...
Run Code Online (Sandbox Code Playgroud)这是我的background.js,我暂时做了一个快速的功能,试图根据一个开关来打开/关闭onClicked
var status = 0;
function toggle() {
if (status == 0){
chrome.browserAction.setIcon({path: "on.png", tabId:tab.id}); // so it's set for the tab user is in
chrome.tabs.executeScript(tab.id, file:"SCRIPT.user.js"); //execute for this tab
status++;
}
if (status == 1){
chrome.browserAction.setIcon({path: …Run Code Online (Sandbox Code Playgroud)javascript google-chrome google-chrome-extension content-script
我是PHP新手并使用静态变量练习.我决定抓住一个我从C++学到的例子并重新编写它用于PHP(例如本文的底部).
有一个类有两个私有变量(一个静态),一个构造函数和一个get-method.构造函数将静态变量的值分配给第二个私有变量,然后递增.
<?php
class Something
{
private static $s_nIDGenerator = 1;
private $m_nID;
public function Something() {
$m_nID = self::$s_nIDGenerator++;
echo "m_nID: " . $m_nID . "</br>"; //for testing, can comment this out
}
public function GetID() {
return $m_nID;
}
}
// extra question:
// static variable can be assigned a value outside the class in C++, why not in PHP?
// Something::$s_nIDGenerator = 1;
$cFirst = new Something();
$cSecond = new Something();
$cThird = new Something(); …Run Code Online (Sandbox Code Playgroud) 有一个API对象的解决方法函数,调用unsafeWindow不支持它的浏览器(通过这个人的github)
var unsafeWindow = (function() {
var e1 = document.createElement('p')
e1.setAttribute('onclick', 'return window;');
return e1.onclick();
})();
// If the current document uses a JavaScript library, you can use it in
// your user script like this:
console.log(unsafeWindow.jQuery);
Run Code Online (Sandbox Code Playgroud)
如果unsafeWindow是一个对象(或者在这种情况下是一个模仿对象的函数),它怎么能用到$ = unsafeWindow.jQuery?我知道这是你如何将函数映射到$而不是$简单的jQuery别名,但我只是为什么,因为我认为jQuery自己是一个对象,并在这里被调用,就像一个方法.
编辑:感谢您的回答,我希望我能"勾选"所有人,感谢您的帮助!