Skip to content

Commit

Permalink
更新CSSStyleSheet样式方法
Browse files Browse the repository at this point in the history
  • Loading branch information
example committed Nov 9, 2020
1 parent 0e585d6 commit 8e39766
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
20 changes: 11 additions & 9 deletions translate/translate-dictionary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 划词翻译:多词典查询
// @namespace http://tampermonkey.net/
// @version 6.9
// @version 8
// @description 划词翻译调用“有道词典(有道翻译)、金山词霸、Bing 词典(必应词典)、剑桥高阶、沪江小D、谷歌翻译”
// @author https://github.com/barrer
// @match http://*/*
Expand Down Expand Up @@ -557,16 +557,18 @@
/**解决 Content-Security-Policy 样式文件加载问题(Chrome 实验功能)*/
function adoptedStyleSheets(bindDocumentOrShadowRoot, cssText) {
try {
cssText = cssText.replace(/\/\*.*?\*\//ig, ''); // remove CSS comments
var cssSheet = new CSSStyleSheet();
var styleArray = cssText.split('\n');
for (var i = 0; i < styleArray.length; i++) {
var line = styleArray[i].trim();
if (line.length > 0) {
cssSheet.insertRule(line);
if (bindDocumentOrShadowRoot.adoptedStyleSheets) {
cssText = cssText.replace(/\/\*.*?\*\//ig, ''); // remove CSS comments
var cssSheet = new CSSStyleSheet();
var styleArray = cssText.split('\n');
for (var i = 0; i < styleArray.length; i++) {
var line = styleArray[i].trim();
if (line.length > 0) {
cssSheet.insertRule(line);
}
}
bindDocumentOrShadowRoot.adoptedStyleSheets = [cssSheet];
}
bindDocumentOrShadowRoot.adoptedStyleSheets = [cssSheet];
} catch (error) {
log(error);
}
Expand Down
20 changes: 11 additions & 9 deletions translate/translate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e39766

Please sign in to comment.