Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

#92: Log an error in case of an unsupported cross-origin HTTP request

  • Loading branch information...
commit c4c9224c8ee239aaac3129114b34836d05a005f3 1 parent d3b4bc4
@kynikos authored
Showing with 36 additions and 6 deletions.
  1. +23 −3 src/modules/MW.js
  2. +13 −3 src/plugins/ArchWikiTemplateAUR.js
View
26 src/modules/MW.js
@@ -113,7 +113,7 @@ WM.MW = new function () {
if (!api) {
api = wikiPaths.local.api;
}
- GM_xmlhttpRequest({
+ var query = {
method: "GET",
url: api + "?format=json" + joinParams(params),
onload: function (res) {
@@ -133,7 +133,18 @@ WM.MW = new function () {
onerror: function (res) {
WM.Log.logError("Failed query: " + res.finalUrl);
}
- });
+ };
+
+ try {
+ GM_xmlhttpRequest(query);
+ }
+ catch (err) {
+ WM.Log.logError("Failed HTTP request - " + err +
+ "\nIf the error above is \"Security violation\" " +
+ "you are probably using Wiki Monkey without " +
+ "Scriptish, Greasemonkey or Tampermonkey: " +
+ "see https://github.com/kynikos/wiki-monkey/wiki");
+ }
};
this.callAPIPost = function (params, api, call, callArgs) {
@@ -190,7 +201,16 @@ WM.MW = new function () {
query.headers = {"Content-type": "application/x-www-form-urlencoded"};
}
- GM_xmlhttpRequest(query);
+ try {
+ GM_xmlhttpRequest(query);
+ }
+ catch (err) {
+ WM.Log.logError("Failed HTTP request - " + err +
+ "\nIf the error above is \"Security violation\" " +
+ "you are probably using Wiki Monkey without " +
+ "Scriptish, Greasemonkey or Tampermonkey: " +
+ "see https://github.com/kynikos/wiki-monkey/wiki");
+ }
};
var joinParams = function (params) {
View
16 src/plugins/ArchWikiTemplateAUR.js
@@ -21,7 +21,7 @@ WM.Plugins.ArchWikiTemplateAUR = new function () {
this.doReplaceContinue = function (source, newText, links, index, call, callArgs) {
if (links[index]) {
WM.Log.logInfo("Processing " + links[index][0] + "...");
- GM_xmlhttpRequest({
+ var query = {
method: "GET",
url: links[index][1],
onload: function (res) {
@@ -44,8 +44,18 @@ WM.Plugins.ArchWikiTemplateAUR = new function () {
},
onerror: function (res) {
WM.Log.logError("Failed query: " + res.finalUrl);
- }
- });
+ },
+ };
+ try {
+ GM_xmlhttpRequest(query);
+ }
+ catch (err) {
+ WM.Log.logError("Failed HTTP request - " + err +
+ "\nIf the error above is \"Security violation\" " +
+ "you are probably using Wiki Monkey without " +
+ "Scriptish, Greasemonkey or Tampermonkey: " +
+ "see https://github.com/kynikos/wiki-monkey/wiki");
+ }
}
else {
call(source, newText, callArgs);
Please sign in to comment.
Something went wrong with that request. Please try again.