feature: add initial openusercss handshake
This commit is contained in:
parent
8821c2f23f
commit
aa31f53448
58
content/install-hook-openusercss.js
Normal file
58
content/install-hook-openusercss.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
'use strict';
|
||||
|
||||
(() => {
|
||||
const manifest = chrome.runtime.getManifest();
|
||||
|
||||
// Tell the page that we exist and that it should send the handshake
|
||||
window.postMessage({
|
||||
'type': 'ouc-begin-handshake'
|
||||
}, '*');
|
||||
|
||||
// Wait for the handshake
|
||||
window.addEventListener('message', event => {
|
||||
if (event.data && event.data.type === 'ouc-handshake-question') {
|
||||
// This is a representation of features that Stylus is capable of
|
||||
const implementedFeatures = [
|
||||
'install-usercss',
|
||||
'configure-after-install',
|
||||
'builtin-editor',
|
||||
'create-usercss',
|
||||
'edit-usercss',
|
||||
'import-moz-export',
|
||||
'export-moz-export',
|
||||
'update-manual',
|
||||
'update-auto',
|
||||
'export-json-backups',
|
||||
'import-json-backups',
|
||||
'manage-local'
|
||||
];
|
||||
const reportedFeatures = [];
|
||||
|
||||
// The handshake question includes a list of required and optional features
|
||||
// we match them with features we have implemented, and build a union array.
|
||||
event.data.featuresList.required.forEach(feature => {
|
||||
if (implementedFeatures.includes(feature)) {
|
||||
reportedFeatures.push(feature);
|
||||
}
|
||||
});
|
||||
|
||||
event.data.featuresList.optional.forEach(feature => {
|
||||
if (implementedFeatures.includes(feature)) {
|
||||
reportedFeatures.push(feature);
|
||||
}
|
||||
});
|
||||
|
||||
// We send the handshake response, which includes the key we got, plus some
|
||||
// additional metadata
|
||||
window.postMessage({
|
||||
'type': 'ouc-handshake-response',
|
||||
'key': event.data.key,
|
||||
'extension': {
|
||||
'name': manifest.name,
|
||||
'version': manifest.version,
|
||||
'capabilities': reportedFeatures
|
||||
}
|
||||
}, '*');
|
||||
}
|
||||
});
|
||||
})();
|
|
@ -60,6 +60,12 @@
|
|||
"all_frames": false,
|
||||
"js": ["content/install-hook-userstyles.js"]
|
||||
},
|
||||
{
|
||||
"matches": ["https://openusercss.org/*", "https://openusercss.com/*"],
|
||||
"run_at": "document_start",
|
||||
"all_frames": false,
|
||||
"js": ["content/install-hook-openusercss.js"]
|
||||
},
|
||||
{
|
||||
"matches": ["<all_urls>"],
|
||||
"include_globs": ["*.user.css", "*.user.styl"],
|
||||
|
|
Loading…
Reference in New Issue
Block a user