-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
66 lines (60 loc) · 2.42 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
// this script uses the write-good library to check
// HTML paragraphs for good writing style
// see https://github.com/btford/write-good for more details
const schreibGut = require('schreib-gut');
const writeGood = require('write-good');
function applyWriteGood() {
let paragraphs = document.getElementsByTagName("p");
let stats = {'oice': 0, 'iage': 0, 'eded': 0, 'ning': 0, 'iche': 0, 'ated': 0, 'word': 0};
const names = {
'oice': 'passive voice',
'iage': 'unnecessary verbiage',
'eded': 'wordy or unneeded',
'ning': 'no meaning',
'iche': 'cliché',
'ated': 'repeated word',
'word': 'weasel word'
};
[].forEach.call(paragraphs, function (paragraph) {
let text = paragraph.textContent;
let suggestions = writeGood(text);
let numSuggestions = document.createElement("span");
numSuggestions.innerHTML = suggestions.length;
paragraph.appendChild(numSuggestions);
let highlighted = "";
let lastIndex = 0;
[].forEach.call(suggestions, function (suggestion) {
console.log(suggestion)
highlighted += text.substr(lastIndex, suggestion.index - lastIndex);
let reason = suggestion.reason;
let type = reason.substr(reason.length - 4);
highlighted += "<span class='mark wg-" + type + "'>";
highlighted += text.substr(suggestion.index, suggestion.offset);
highlighted += "<span class='reason'>" + reason + "</span></span>";
lastIndex = suggestion.index + suggestion.offset;
stats[type] += 1;
});
highlighted += text.substr(lastIndex, text.length - lastIndex);
paragraph.innerHTML = highlighted
});
let output = "";
for (let key in stats) {
console.log(stats[key]);
output += "<tr><td>" + stats[key] + " x</td><td><span class='wg-" + key + "'>" + names[key] + "</span></td></tr>";
}
;
let wgtable = document.getElementById('writegoodtd');
wgtable.innerHTML = output;
}
document.addEventListener("DOMContentLoaded", function() {
// applyWriteGood();
var oldProcessLinks = __IntelliJTools && __IntelliJTools.processLinks;
// if this is in the preview window in the IDE, run the checks
if (oldProcessLinks) {
__IntelliJTools.processLinks = function() {
oldProcessLinks();
applyWriteGood();
}
}
});