Add: findStyle API
This commit is contained in:
parent
8e75871b9b
commit
93a4cdf595
|
@ -9,17 +9,18 @@ var backgroundWorker = workerUtil.createWorker({
|
||||||
});
|
});
|
||||||
|
|
||||||
window.API_METHODS = Object.assign(window.API_METHODS || {}, {
|
window.API_METHODS = Object.assign(window.API_METHODS || {}, {
|
||||||
|
deleteStyle: styleManager.deleteStyle,
|
||||||
|
editSave: styleManager.editSave,
|
||||||
|
findStyle: styleManager.findStyle,
|
||||||
|
getAllStyles: styleManager.getAllStyles, // used by importer
|
||||||
getSectionsByUrl: styleManager.getSectionsByUrl,
|
getSectionsByUrl: styleManager.getSectionsByUrl,
|
||||||
|
getStyle: styleManager.get,
|
||||||
getStylesInfo: styleManager.getStylesInfo,
|
getStylesInfo: styleManager.getStylesInfo,
|
||||||
getStylesInfoByUrl: styleManager.getStylesInfoByUrl,
|
getStylesInfoByUrl: styleManager.getStylesInfoByUrl,
|
||||||
toggleStyle: styleManager.toggleStyle,
|
|
||||||
deleteStyle: styleManager.deleteStyle,
|
|
||||||
installStyle: styleManager.installStyle,
|
|
||||||
editSave: styleManager.editSave,
|
|
||||||
importStyle: styleManager.importStyle,
|
importStyle: styleManager.importStyle,
|
||||||
|
installStyle: styleManager.installStyle,
|
||||||
styleExists: styleManager.styleExists,
|
styleExists: styleManager.styleExists,
|
||||||
getStyle: styleManager.get,
|
toggleStyle: styleManager.toggleStyle,
|
||||||
getAllStyles: styleManager.getAllStyles, // used by importer
|
|
||||||
|
|
||||||
getTabUrlPrefix() {
|
getTabUrlPrefix() {
|
||||||
return this.sender.tab.url.match(/^([\w-]+:\/+[^/#]+)/)[1];
|
return this.sender.tab.url.match(/^([\w-]+:\/+[^/#]+)/)[1];
|
||||||
|
|
|
@ -54,6 +54,7 @@ const styleManager = (() => {
|
||||||
installStyle,
|
installStyle,
|
||||||
deleteStyle,
|
deleteStyle,
|
||||||
editSave,
|
editSave,
|
||||||
|
findStyle,
|
||||||
importStyle,
|
importStyle,
|
||||||
toggleStyle,
|
toggleStyle,
|
||||||
setStyleExclusions,
|
setStyleExclusions,
|
||||||
|
@ -116,6 +117,16 @@ const styleManager = (() => {
|
||||||
.map(s => getStyleWithNoCode(s.data));
|
.map(s => getStyleWithNoCode(s.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// used by install-hook-userstyles.js
|
||||||
|
function findStyle(filter) {
|
||||||
|
for (const style of styles.values()) {
|
||||||
|
if (filterMatch(filter, style.data)) {
|
||||||
|
return style.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function styleExists(filter) {
|
function styleExists(filter) {
|
||||||
return [...styles.value()].some(s => filterMatch(filter, s.data));
|
return [...styles.value()].some(s => filterMatch(filter, s.data));
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
gotBody = true;
|
gotBody = true;
|
||||||
// TODO: remove the following statement when USO pagination title is fixed
|
// TODO: remove the following statement when USO pagination title is fixed
|
||||||
document.title = document.title.replace(/^(\d+)&\w+=/, '#$1: ');
|
document.title = document.title.replace(/^(\d+)&\w+=/, '#$1: ');
|
||||||
API.getStylesInfo({
|
API.findStyle({
|
||||||
md5Url: getMeta('stylish-md5-url') || location.href
|
md5Url: getMeta('stylish-md5-url') || location.href
|
||||||
}).then(checkUpdatability);
|
}).then(checkUpdatability);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
return jsonUrl + (paramsMissing ? textUrl.replace(/^[^?]+/, '') : '');
|
return jsonUrl + (paramsMissing ? textUrl.replace(/^[^?]+/, '') : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUpdatability([installedStyle]) {
|
function checkUpdatability(installedStyle) {
|
||||||
// TODO: remove the following statement when USO is fixed
|
// TODO: remove the following statement when USO is fixed
|
||||||
document.dispatchEvent(new CustomEvent('stylusFixBuggyUSOsettings', {
|
document.dispatchEvent(new CustomEvent('stylusFixBuggyUSOsettings', {
|
||||||
detail: installedStyle && installedStyle.updateUrl,
|
detail: installedStyle && installedStyle.updateUrl,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user