chrome.extension.sendMessage -> chrome.runtime.sendMessage
This commit is contained in:
parent
8f10fc291e
commit
d957cd1b3b
4
apply.js
4
apply.js
|
@ -19,7 +19,7 @@ function requestStyles() {
|
||||||
bg.getStyles(request, applyStyles);
|
bg.getStyles(request, applyStyles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chrome.extension.sendMessage(request, applyStyles);
|
chrome.runtime.sendMessage(request, applyStyles);
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
|
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
|
||||||
|
@ -38,7 +38,7 @@ chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
|
||||||
}
|
}
|
||||||
case "styleAdded":
|
case "styleAdded":
|
||||||
if (request.style.enabled == "true") {
|
if (request.style.enabled == "true") {
|
||||||
chrome.extension.sendMessage({method: "getStyles", matchUrl: location.href, enabled: true, id: request.style.id, asHash: true}, applyStyles);
|
chrome.runtime.sendMessage({method: "getStyles", matchUrl: location.href, enabled: true, id: request.style.id, asHash: true}, applyStyles);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "styleApply":
|
case "styleApply":
|
||||||
|
|
4
edit.js
4
edit.js
|
@ -1079,7 +1079,7 @@ function init() {
|
||||||
tE("heading", "editStyleHeading", null, false);
|
tE("heading", "editStyleHeading", null, false);
|
||||||
requestStyle();
|
requestStyle();
|
||||||
function requestStyle() {
|
function requestStyle() {
|
||||||
chrome.extension.sendMessage({method: "getStyles", id: params.id}, function callback(styles) {
|
chrome.runtime.sendMessage({method: "getStyles", id: params.id}, function callback(styles) {
|
||||||
if (!styles) { // Chrome is starting up and shows edit.html
|
if (!styles) { // Chrome is starting up and shows edit.html
|
||||||
requestStyle();
|
requestStyle();
|
||||||
return;
|
return;
|
||||||
|
@ -1247,7 +1247,7 @@ function save() {
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
sections: getSectionsHashes()
|
sections: getSectionsHashes()
|
||||||
};
|
};
|
||||||
chrome.extension.sendMessage(request, saveComplete);
|
chrome.runtime.sendMessage(request, saveComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSectionsHashes() {
|
function getSectionsHashes() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
healthCheck();
|
healthCheck();
|
||||||
|
|
||||||
function healthCheck() {
|
function healthCheck() {
|
||||||
chrome.extension.sendMessage({method: "healthCheck"}, function(ok) {
|
chrome.runtime.sendMessage({method: "healthCheck"}, function(ok) {
|
||||||
if (ok === undefined) { // Chrome is starting up
|
if (ok === undefined) { // Chrome is starting up
|
||||||
healthCheck();
|
healthCheck();
|
||||||
} else if (!ok && confirm(t("dbError"))) {
|
} else if (!ok && confirm(t("dbError"))) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
chrome.extension.sendMessage({method: "getStyles", url: getMeta("stylish-id-url") || location.href}, function(response) {
|
chrome.runtime.sendMessage({method: "getStyles", url: getMeta("stylish-id-url") || location.href}, function(response) {
|
||||||
if (response.length == 0) {
|
if (response.length == 0) {
|
||||||
sendEvent("styleCanBeInstalledChrome");
|
sendEvent("styleCanBeInstalledChrome");
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,7 +76,7 @@ document.addEventListener("stylishInstallChrome", function() {
|
||||||
// check for old style json
|
// check for old style json
|
||||||
var json = JSON.parse(code);
|
var json = JSON.parse(code);
|
||||||
json.method = "saveStyle";
|
json.method = "saveStyle";
|
||||||
chrome.extension.sendMessage(json, function(response) {
|
chrome.runtime.sendMessage(json, function(response) {
|
||||||
sendEvent("styleInstalledChrome");
|
sendEvent("styleInstalledChrome");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -86,14 +86,14 @@ document.addEventListener("stylishInstallChrome", function() {
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
document.addEventListener("stylishUpdateChrome", function() {
|
document.addEventListener("stylishUpdateChrome", function() {
|
||||||
chrome.extension.sendMessage({method: "getStyles", url: getMeta("stylish-id-url") || location.href}, function(response) {
|
chrome.runtime.sendMessage({method: "getStyles", url: getMeta("stylish-id-url") || location.href}, function(response) {
|
||||||
var style = response[0];
|
var style = response[0];
|
||||||
if (confirm(chrome.i18n.getMessage('styleUpdate', [style.name]))) {
|
if (confirm(chrome.i18n.getMessage('styleUpdate', [style.name]))) {
|
||||||
getResource(getMeta("stylish-code-chrome"), function(code) {
|
getResource(getMeta("stylish-code-chrome"), function(code) {
|
||||||
var json = JSON.parse(code);
|
var json = JSON.parse(code);
|
||||||
json.method = "saveStyle";
|
json.method = "saveStyle";
|
||||||
json.id = style.id;
|
json.id = style.id;
|
||||||
chrome.extension.sendMessage(json, function() {
|
chrome.runtime.sendMessage(json, function() {
|
||||||
sendEvent("styleInstalledChrome");
|
sendEvent("styleInstalledChrome");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
12
manage.js
12
manage.js
|
@ -5,11 +5,11 @@ var appliesToExtraTemplate = document.createElement("span");
|
||||||
appliesToExtraTemplate.className = "applies-to-extra";
|
appliesToExtraTemplate.className = "applies-to-extra";
|
||||||
appliesToExtraTemplate.innerHTML = " " + t('appliesDisplayTruncatedSuffix');
|
appliesToExtraTemplate.innerHTML = " " + t('appliesDisplayTruncatedSuffix');
|
||||||
|
|
||||||
chrome.extension.sendMessage({method: "getStyles"}, showStyles);
|
chrome.runtime.sendMessage({method: "getStyles"}, showStyles);
|
||||||
|
|
||||||
function showStyles(styles) {
|
function showStyles(styles) {
|
||||||
if (!styles) { // Chrome is starting up
|
if (!styles) { // Chrome is starting up
|
||||||
chrome.extension.sendMessage({method: "getStyles"}, showStyles);
|
chrome.runtime.sendMessage({method: "getStyles"}, showStyles);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!installed) {
|
if (!installed) {
|
||||||
|
@ -114,7 +114,7 @@ function createStyleElement(style) {
|
||||||
options.url = url;
|
options.url = url;
|
||||||
chrome.windows.create(options);
|
chrome.windows.create(options);
|
||||||
} else {
|
} else {
|
||||||
chrome.extension.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
method: "openURL",
|
method: "openURL",
|
||||||
url: url,
|
url: url,
|
||||||
active: openForegroundTab
|
active: openForegroundTab
|
||||||
|
@ -251,7 +251,7 @@ function checkUpdate(element, callback) {
|
||||||
var originalMd5 = element.getAttribute("style-original-md5");
|
var originalMd5 = element.getAttribute("style-original-md5");
|
||||||
|
|
||||||
function handleSuccess(forceUpdate, serverJson) {
|
function handleSuccess(forceUpdate, serverJson) {
|
||||||
chrome.extension.sendMessage({method: "getStyles", id: id}, function(styles) {
|
chrome.runtime.sendMessage({method: "getStyles", id: id}, function(styles) {
|
||||||
var style = styles[0];
|
var style = styles[0];
|
||||||
var needsUpdate = false;
|
var needsUpdate = false;
|
||||||
if (!forceUpdate && codeIsEqual(style.sections, serverJson.sections)) {
|
if (!forceUpdate && codeIsEqual(style.sections, serverJson.sections)) {
|
||||||
|
@ -362,7 +362,7 @@ function doUpdate(event) {
|
||||||
|
|
||||||
// updating the UI will be handled by the general update listener
|
// updating the UI will be handled by the general update listener
|
||||||
lastUpdatedStyleId = updatedCode.id;
|
lastUpdatedStyleId = updatedCode.id;
|
||||||
chrome.extension.sendMessage(updatedCode);
|
chrome.runtime.sendMessage(updatedCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function codeIsEqual(a, b) {
|
function codeIsEqual(a, b) {
|
||||||
|
@ -430,7 +430,7 @@ function searchStyles(immediately) {
|
||||||
searchStyles.timeout = setTimeout(doSearch, 100);
|
searchStyles.timeout = setTimeout(doSearch, 100);
|
||||||
}
|
}
|
||||||
function doSearch() {
|
function doSearch() {
|
||||||
chrome.extension.sendMessage({method: "getStyles"}, function(styles) {
|
chrome.runtime.sendMessage({method: "getStyles"}, function(styles) {
|
||||||
styles.forEach(function(style) {
|
styles.forEach(function(style) {
|
||||||
var el = document.querySelector("[style-id='" + style.id + "']");
|
var el = document.querySelector("[style-id='" + style.id + "']");
|
||||||
if (el) {
|
if (el) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ function notifyAllTabs(request) {
|
||||||
});
|
});
|
||||||
// notify all open popups
|
// notify all open popups
|
||||||
var reqPopup = shallowMerge({}, request, {method: "updatePopup", reason: request.method});
|
var reqPopup = shallowMerge({}, request, {method: "updatePopup", reason: request.method});
|
||||||
chrome.extension.sendMessage(reqPopup);
|
chrome.runtime.sendMessage(reqPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateIcon(tab, styles) {
|
function updateIcon(tab, styles) {
|
||||||
|
@ -39,7 +39,7 @@ function updateIcon(tab, styles) {
|
||||||
if (typeof getStyles != "undefined") {
|
if (typeof getStyles != "undefined") {
|
||||||
getStyles({matchUrl: url, enabled: true}, stylesReceived);
|
getStyles({matchUrl: url, enabled: true}, stylesReceived);
|
||||||
} else {
|
} else {
|
||||||
chrome.extension.sendMessage({method: "getStyles", matchUrl: url, enabled: true}, stylesReceived);
|
chrome.runtime.sendMessage({method: "getStyles", matchUrl: url, enabled: true}, stylesReceived);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
4
popup.js
4
popup.js
|
@ -17,7 +17,7 @@ function updatePopUp(url) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.extension.sendMessage({method: "getStyles", matchUrl: url}, showStyles);
|
chrome.runtime.sendMessage({method: "getStyles", matchUrl: url}, showStyles);
|
||||||
document.querySelector("#find-styles a").href = "https://userstyles.org/styles/browse/all/" + encodeURIComponent("file" === urlWillWork[1] ? "file:" : url);
|
document.querySelector("#find-styles a").href = "https://userstyles.org/styles/browse/all/" + encodeURIComponent("file" === urlWillWork[1] ? "file:" : url);
|
||||||
|
|
||||||
// Write new style links
|
// Write new style links
|
||||||
|
@ -159,7 +159,7 @@ function openLinkInTabOrWindow(event) {
|
||||||
|
|
||||||
function openLink(event) {
|
function openLink(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
chrome.extension.sendMessage({method: "openURL", url: event.target.href});
|
chrome.runtime.sendMessage({method: "openURL", url: event.target.href});
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ function enableStyle(id, enabled) {
|
||||||
db.transaction(function (t) {
|
db.transaction(function (t) {
|
||||||
t.executeSql("UPDATE styles SET enabled = ? WHERE id = ?;", [enabled, id]);
|
t.executeSql("UPDATE styles SET enabled = ? WHERE id = ?;", [enabled, id]);
|
||||||
}, reportError, function() {
|
}, reportError, function() {
|
||||||
chrome.extension.sendMessage({method: "styleChanged"});
|
chrome.runtime.sendMessage({method: "styleChanged"});
|
||||||
chrome.extension.sendMessage({method: "getStyles", id: id}, function(styles) {
|
chrome.runtime.sendMessage({method: "getStyles", id: id}, function(styles) {
|
||||||
handleUpdate(styles[0]);
|
handleUpdate(styles[0]);
|
||||||
notifyAllTabs({method: "styleUpdated", style: styles[0]});
|
notifyAllTabs({method: "styleUpdated", style: styles[0]});
|
||||||
});
|
});
|
||||||
|
@ -93,7 +93,7 @@ function deleteStyle(id) {
|
||||||
t.executeSql('DELETE FROM sections WHERE style_id = ?;', [id]);
|
t.executeSql('DELETE FROM sections WHERE style_id = ?;', [id]);
|
||||||
t.executeSql("DELETE FROM styles WHERE id = ?;", [id]);
|
t.executeSql("DELETE FROM styles WHERE id = ?;", [id]);
|
||||||
}, reportError, function() {
|
}, reportError, function() {
|
||||||
chrome.extension.sendMessage({method: "styleChanged"});
|
chrome.runtime.sendMessage({method: "styleChanged"});
|
||||||
handleDelete(id);
|
handleDelete(id);
|
||||||
notifyAllTabs({method: "styleDeleted", id: id});
|
notifyAllTabs({method: "styleDeleted", id: id});
|
||||||
});
|
});
|
||||||
|
@ -232,7 +232,7 @@ var prefs = chrome.extension.getBackgroundPage().prefs || new function Prefs() {
|
||||||
Prefs.prototype.broadcast = function(key, value, options) {
|
Prefs.prototype.broadcast = function(key, value, options) {
|
||||||
var message = {method: "prefChanged", prefName: key, value: value};
|
var message = {method: "prefChanged", prefName: key, value: value};
|
||||||
notifyAllTabs(message);
|
notifyAllTabs(message);
|
||||||
chrome.extension.sendMessage(message);
|
chrome.runtime.sendMessage(message);
|
||||||
if (key == "disableAll") {
|
if (key == "disableAll") {
|
||||||
notifyAllTabs({method: "styleDisableAll", disableAll: value});
|
notifyAllTabs({method: "styleDisableAll", disableAll: value});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user