Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
suggestor | ||
config.toml | ||
|
||
webext/node_modules | ||
webext/web-ext-artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "eslint:recommended", | ||
"env": { | ||
"es6": true, | ||
"browser": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"esversion": 6, | ||
"browser": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* global $,mw,ve,OO */ | ||
let inject = function() { | ||
const SUGGESTOR_URI = "https://tools.wmflabs.org/suggestor/post"; | ||
|
||
let post = function(summary, wikitext) { | ||
let target = ve.init.target; | ||
|
||
// FIXME: There's gotta be some canonical way of doing this. | ||
let api = $("link[rel=EditURI]").attr("href"); | ||
api = api.replace(/\?.*$/, ""); | ||
if (/^\/\//.test(api)) { | ||
api = location.protocol + api; | ||
} | ||
|
||
$.ajax({ | ||
type: "post", | ||
url: SUGGESTOR_URI, | ||
dataType: "json", | ||
data: JSON.stringify({ | ||
api: api, | ||
wikitext: wikitext, | ||
summary: summary, | ||
revid: mw.config.get("wgRevisionId"), | ||
pageid: mw.config.get("wgArticleId"), | ||
pagename: mw.config.get("wgPageName"), | ||
}), | ||
success: function() { | ||
target.saveDialog.reset(); | ||
mw.hook("postEdit").fire({ message: "Edit suggested!" }); | ||
target.deactivate(true); | ||
}, | ||
error: function() { | ||
target.showSaveError("Failed to suggest edit.", true, true); | ||
}, | ||
}); | ||
}; | ||
|
||
mw.libs.ve.targetLoader.addPlugin(function() { | ||
let torget = function(config) { | ||
torget.super.call(this, config); | ||
}; | ||
OO.inheritClass(torget, ve.init.mw.DesktopArticleTarget); | ||
torget.prototype.save = function(doc, options) { | ||
ve.init.target.serialize(doc, post.bind(null, options.summary)); | ||
}; | ||
ve.init.mw.targetFactory.register(torget); | ||
}); | ||
|
||
mw.hook("postEdit").fire({ message: "Suggestor loaded." }); | ||
}; | ||
|
||
// `content_scripts` can't see variables defined by page scripts, but we want | ||
// to use the mw apis, so let's inject the script in the page. | ||
let script = document.createElement("script"); | ||
script.setAttribute("id", "suggestor"); | ||
script.appendChild(document.createTextNode(inject.toSource() + "();")); | ||
document.body.appendChild(script); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "Suggestor", | ||
"version": "0.0.0", | ||
"description": "Suggest edits.", | ||
"applications": { | ||
"gecko": { | ||
"id": "suggestor@wmflabs", | ||
"strict_min_version": "45.0" | ||
} | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["*://*.wikipedia.org/wiki/*"], | ||
"js": [ "index.js" ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "suggestor", | ||
"version": "0.0.0", | ||
"description": "Suggest edits.", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^3.12.2", | ||
"jshint": "^2.9.4", | ||
"web-ext": "^1.6.0" | ||
}, | ||
"scripts": { | ||
"build": "web-ext build", | ||
"eslint": "eslint --ext .js .", | ||
"jshint": "jshint *.js", | ||
"lint": "npm run wlint && npm run jshint && npm run eslint", | ||
"wlint": "web-ext lint" | ||
} | ||
} |