fairlanguage-firefox/content_scripts/fairlang.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-10-16 23:03:04 +02:00
// ---------------------------------
// Content script to be run on pages
// ---------------------------------
2018-10-09 18:18:42 +02:00
2018-10-16 23:48:40 +02:00
function checkTextarea(textarea) {
console.log("click " + textarea.id + " -> " + textarea.value);
// TODO make queries to the fairlanguage server
2018-10-17 00:33:22 +02:00
fetch("https://fairlanguage2.dev-star.de/checkDocument?data=liebe+Bürger&json")
.then(response => response.json())
.then(response => {
console.log(response);
})
.catch(error => console.log(error));
2018-10-16 23:48:40 +02:00
}
2018-10-16 23:03:04 +02:00
(function() {
// Only run this script once
if (window.hasRun) {
return;
}
window.hasRun = true;
// Search for all text areas
document.querySelectorAll("textarea").forEach(function(textarea) {
2018-10-16 23:48:40 +02:00
// for testing: highlight textarea with red border
// TODO
2018-10-16 23:03:04 +02:00
textarea.style.border = "2px solid red";
2018-10-16 23:48:40 +02:00
// Create a "Check fairness" button which is placed next to the textarea
// TODO image button integrated into the textarea...
var buttonCheck = document.createElement("button");
buttonCheck.textContent = "Check fairness!";
// Add click event listener
buttonCheck.addEventListener("click", (e) => {
checkTextarea(textarea);
});
// Append button to the textarea
textarea.after(buttonCheck);
});
2018-10-16 23:03:04 +02:00
})();