forked from wuyawei/fe-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource-inject.js
More file actions
23 lines (22 loc) · 794 Bytes
/
Copy pathresource-inject.js
File metadata and controls
23 lines (22 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* global chrome*/
// noinspection JSUnresolvedVariable
chrome.runtime.onMessage.addListener(function(request) { // background返回的回调消息
console.log('request', request)
const addScript = (link) => {
const theScript = document.createElement('script');
theScript.src = link;
document.documentElement.appendChild(theScript);
};
const addStyle = (link) => {
const d = document.createElement('link');
d.href = link;
d.rel="stylesheet";
document.documentElement.appendChild(d);
};
if (request.type === 'fetch-resource') {
console.log('fetch-resource');
request.contentType === "stylesheet"
? request.links.forEach(addStyle)
: request.links.forEach(addScript)
}
});