脚本的直接链接:https://github.com/MosheBerman/MinimalOverflow/blob/master/styleswitcher.user.js
我从 https://stackapps.com/questions/2143/minimaloverflow-a-themescript-for-stack-exchange 下载了一个脚本并将 *.user.js 文件拖放到 Chrome 中我的扩展选项卡中。脚本运行,我使用 alert
验证了这一点。我什至 alert
编辑了脚本中的 href
属性以验证它是否正确更改了它。
本质上,代码查找 link
标记并更改 href
属性。
第 64 行
function switchToStylesheet(sheet){
for(var i=0; i<linkElements.length; i++){
if(linkElements[i].getAttribute("rel") == "stylesheet"){
//apply the new stylesheet
linkElements[i].href = sheet;
alert(linksElements[i].href);
// shows https://github.com/MosheBerman/MinimalOverflow/raw/master/clean.css as expected
//We only want to replace the first stylesheet, so return.
//If SO decides to change any styles, just put it in a
//second stylesheet and link tag. The script should safely ignore it.
return;
}
}
}
我有 版本 25.0.1364.152
我正在运行 Windows 7 64 位
谁能验证这是 Chrome
、Javascript
还是 Userscript
问题?
最佳答案
参见 "Referencing a .css file in github repo as stylesheet in a .html file" . Git 使用错误的 MIME 类型提供 CSS 文件 (.../raw/master/clean.css
);因此 Chrome 和 Firefox 等浏览器不会(通常)处理/应用此类 CSS。
快速解决方法是将该 CSS 文件托管在您自己的服务器或免费文件托管站点之一上。然后将脚本设置更改为:
var pathToNewStylesheet = "http://YOUR_SERVER.COM/YOUR_PATH/clean.css";
关于javascript - Chrome 用户脚本未应用远程 CSS 样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16333559/