generate stylus-firefox.zip without declarativeContent
This commit is contained in:
parent
818f6313c6
commit
1d1d75d2ac
|
@ -45,11 +45,8 @@ CHROME && (async () => {
|
||||||
actions: [
|
actions: [
|
||||||
new chrome.declarativeContent.RequestContentScript({
|
new chrome.declarativeContent.RequestContentScript({
|
||||||
allFrames: true,
|
allFrames: true,
|
||||||
js: [
|
// This runs earlier than document_start
|
||||||
'/content/style-via-xhr.js',
|
js: chrome.runtime.getManifest().content_scripts[0].js,
|
||||||
// This sets them to run earlier than document_start
|
|
||||||
...chrome.runtime.getManifest().content_scripts[0].js,
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -57,13 +57,25 @@ self.INJECTED !== 1 && (() => {
|
||||||
if (STYLE_VIA_API) {
|
if (STYLE_VIA_API) {
|
||||||
await API.styleViaAPI({method: 'styleApply'});
|
await API.styleViaAPI({method: 'styleApply'});
|
||||||
} else {
|
} else {
|
||||||
const styles = Array.isArray(window.STYLES) && window.STYLES[0] ||
|
const styles = chrome.app && getStylesViaXhr() || await API.getSectionsByUrl(getMatchUrl());
|
||||||
await API.getSectionsByUrl(getMatchUrl());
|
|
||||||
delete window.STYLES;
|
|
||||||
await styleInjector.apply(styles);
|
await styleInjector.apply(styles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getStylesViaXhr() {
|
||||||
|
if (new RegExp(`(^|\\s|;)${chrome.runtime.id}=\\s*([-\\w]+)\\s*(;|$)`).test(document.cookie)) {
|
||||||
|
const url = 'blob:' + chrome.runtime.getURL(RegExp.$2);
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
document.cookie = `${chrome.runtime.id}=1; max-age=0`; // remove our cookie
|
||||||
|
try {
|
||||||
|
xhr.open('GET', url, false); // synchronous
|
||||||
|
xhr.send();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
return JSON.parse(xhr.response);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getMatchUrl() {
|
function getMatchUrl() {
|
||||||
let matchUrl = location.href;
|
let matchUrl = location.href;
|
||||||
if (!chrome.tabs && !matchUrl.match(/^(http|file|chrome|ftp)/)) {
|
if (!chrome.tabs && !matchUrl.match(/^(http|file|chrome|ftp)/)) {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-expressions
|
|
||||||
self.INJECTED !== 1 &&
|
|
||||||
!(document instanceof XMLDocument && !chrome.app) && // this is STYLE_VIA_API
|
|
||||||
new RegExp(`(^|\\s|;)${chrome.runtime.id}=\\s*([-\\w]+)\\s*(;|$)`).test(document.cookie) &&
|
|
||||||
(() => {
|
|
||||||
const url = 'blob:' + chrome.runtime.getURL(RegExp.$2);
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
document.cookie = `${chrome.runtime.id}=1; max-age=0`;
|
|
||||||
try {
|
|
||||||
xhr.open('GET', url, false); // synchronous
|
|
||||||
xhr.send();
|
|
||||||
// guarding against an implicit global variable for a DOM element with id="STYLES"
|
|
||||||
window.STYLES = [JSON.parse(xhr.response)];
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
} catch (e) {}
|
|
||||||
})();
|
|
29
tools/zip.js
29
tools/zip.js
|
@ -3,10 +3,11 @@
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const archiver = require('archiver');
|
const archiver = require('archiver');
|
||||||
|
const manifest = require('../manifest.json');
|
||||||
|
|
||||||
function createZip() {
|
function createZip({isFirefox} = {}) {
|
||||||
const fileName = 'stylus.zip';
|
const fileName = `stylus${isFirefox ? '-firefox' : ''}.zip`;
|
||||||
const exclude = [
|
const ignore = [
|
||||||
'.*', // dot files/folders (glob, not regexp)
|
'.*', // dot files/folders (glob, not regexp)
|
||||||
'vendor/codemirror/lib/**', // get unmodified copy from node_modules
|
'vendor/codemirror/lib/**', // get unmodified copy from node_modules
|
||||||
'node_modules/**',
|
'node_modules/**',
|
||||||
|
@ -38,15 +39,25 @@ function createZip() {
|
||||||
});
|
});
|
||||||
|
|
||||||
archive.pipe(file);
|
archive.pipe(file);
|
||||||
archive.glob('**', {ignore: exclude});
|
if (isFirefox) {
|
||||||
|
const name = 'manifest.json';
|
||||||
|
const keyOpt = 'optional_permissions';
|
||||||
|
ignore.unshift(name);
|
||||||
|
manifest[keyOpt] = manifest[keyOpt].filter(p => p !== 'declarativeContent');
|
||||||
|
if (!manifest[keyOpt].length) {
|
||||||
|
delete manifest[keyOpt];
|
||||||
|
}
|
||||||
|
archive.append(JSON.stringify(manifest, null, ' '), {name, stats: fs.lstatSync(name)});
|
||||||
|
}
|
||||||
|
archive.glob('**', {ignore});
|
||||||
// Don't use modified codemirror.js (see "update-libraries.js")
|
// Don't use modified codemirror.js (see "update-libraries.js")
|
||||||
archive.directory('node_modules/codemirror/lib', 'vendor/codemirror/lib');
|
archive.directory('node_modules/codemirror/lib', 'vendor/codemirror/lib');
|
||||||
archive.finalize();
|
archive.finalize();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createZip()
|
(async () => {
|
||||||
.then(() => console.log('\x1b[32m%s\x1b[0m', 'Stylus zip complete'))
|
await createZip();
|
||||||
.catch(err => {
|
await createZip({isFirefox: true});
|
||||||
throw err;
|
console.log('\x1b[32m%s\x1b[0m', 'Stylus zip complete');
|
||||||
});
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user