在 css 的路上...
我尝试在一个已经加载的页面上插入一些 css 并且滚动条从未改变?
chrome.tabs.insertCSS(tab.id,{code:"::-webkit-scrollbar {width: 0 !important; height: 0 !important}"});
...甚至尝试将其连接到头部,但也没有用....
insertNoScrollBars=function (){
if(document.getElementById('HideScrollBars') == null){
var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('style');
cssNode.setAttribute('id','HideScrollBars');
cssNode.innerText="::-webkit-scrollbar {width: 0 !important; height: 0 !important}"
headID.appendChild(cssNode);
}
}
chrome.tabs.query({'active': true, 'windowId': chrome.windows.WINDOW_ID_CURRENT},
function(tab){
chrome.tabs.executeScript(tab.id,{code:"("+insertNoScrollBars+")()"});
//chrome.tabs.insertCSS(tab.id,{code:"::-webkit-scrollbar {width: 0 !important; height: 0 !important}"});
}
);
环顾四周,除非有某种刷新,否则滚动条似乎不会更新?....
http://userscripts.org/scripts/show/117089
确实有效的一件事(尽管它可能不适合您的需求)是使用清单中的内容脚本设置注入 css....
manifest.json
{
"name": "Hide scrollbars",
"version": "1.0",
"description": "As the name says",
"permissions": [
"bookmarks", "tabs", "<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["mystyles.css"],
"run_at" : "document_start"
}
]
}
mystyles.css
::-webkit-scrollbar {width: 0 !important; height: 0 !important}
或者
如果您想以编程方式注入它的唯一原因是只有在您的设置要求时才注入它,那么您可以在文档开始时使用内容脚本注入它.....
manifest.json
{
"name": "Hide scrollbars",
"version": "1.0",
"description": "As the name says",
"permissions": [
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"],
"run_at" : "document_start"
}
]
}
content.js
// Do a check here to see if your settings say to hide the scrollbars or not
if(document.getElementById('HideScrollBars') == null){
var headID = document.documentElement;
var cssNode = document.createElement('style');
cssNode.setAttribute('id','HideScrollBars');
cssNode.innerText="::-webkit-scrollbar {width: 0 !important; height: 0 !important}"
headID.appendChild(cssNode);
}