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 || {}, {
|
||||
deleteStyle: styleManager.deleteStyle,
|
||||
editSave: styleManager.editSave,
|
||||
findStyle: styleManager.findStyle,
|
||||
getAllStyles: styleManager.getAllStyles, // used by importer
|
||||
getSectionsByUrl: styleManager.getSectionsByUrl,
|
||||
getStyle: styleManager.get,
|
||||
getStylesInfo: styleManager.getStylesInfo,
|
||||
getStylesInfoByUrl: styleManager.getStylesInfoByUrl,
|
||||
toggleStyle: styleManager.toggleStyle,
|
||||
deleteStyle: styleManager.deleteStyle,
|
||||
installStyle: styleManager.installStyle,
|
||||
editSave: styleManager.editSave,
|
||||
importStyle: styleManager.importStyle,
|
||||
installStyle: styleManager.installStyle,
|
||||
styleExists: styleManager.styleExists,
|
||||
getStyle: styleManager.get,
|
||||
getAllStyles: styleManager.getAllStyles, // used by importer
|
||||
toggleStyle: styleManager.toggleStyle,
|
||||
|
||||
getTabUrlPrefix() {
|
||||
return this.sender.tab.url.match(/^([\w-]+:\/+[^/#]+)/)[1];
|
||||
|
|
|
@ -54,6 +54,7 @@ const styleManager = (() => {
|
|||
installStyle,
|
||||
deleteStyle,
|
||||
editSave,
|
||||
findStyle,
|
||||
importStyle,
|
||||
toggleStyle,
|
||||
setStyleExclusions,
|
||||
|
@ -116,6 +117,16 @@ const styleManager = (() => {
|
|||
.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) {
|
||||
return [...styles.value()].some(s => filterMatch(filter, s.data));
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
gotBody = true;
|
||||
// TODO: remove the following statement when USO pagination title is fixed
|
||||
document.title = document.title.replace(/^(\d+)&\w+=/, '#$1: ');
|
||||
API.getStylesInfo({
|
||||
API.findStyle({
|
||||
md5Url: getMeta('stylish-md5-url') || location.href
|
||||
}).then(checkUpdatability);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@
|
|||
return jsonUrl + (paramsMissing ? textUrl.replace(/^[^?]+/, '') : '');
|
||||
}
|
||||
|
||||
function checkUpdatability([installedStyle]) {
|
||||
function checkUpdatability(installedStyle) {
|
||||
// TODO: remove the following statement when USO is fixed
|
||||
document.dispatchEvent(new CustomEvent('stylusFixBuggyUSOsettings', {
|
||||
detail: installedStyle && installedStyle.updateUrl,
|
||||
|
|
Loading…
Reference in New Issue
Block a user