76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
// ==Bookmarklet==
|
|
// @name Shapr-Their-Replies
|
|
// @author Glenn Y. Rolland
|
|
// ==/Bookmarklet==
|
|
(function() {
|
|
"use strict";
|
|
|
|
const MODE_ALL = 'all';
|
|
const MODE_NEW = 'new';
|
|
|
|
let mode = MODE_ALL;
|
|
|
|
let meetBtnLink = document.querySelector('.menu [href="/meet-pending"]');
|
|
let meetBtn = meetBtnLink.parentNode;
|
|
|
|
let container = meetBtn.parentNode;
|
|
|
|
let allBtn = meetBtn.cloneNode(true);
|
|
let newBtn = meetBtn.cloneNode(true);
|
|
|
|
allBtn.innerHTML = '<a href="">All messages</a>';
|
|
newBtn.innerHTML = '<a href="">New messages only</a>';
|
|
|
|
// let theirsBtn = meetBtn.cloneNode(true);
|
|
// let mineBtn = meetBtn.closeNode(true);
|
|
|
|
container.insertBefore(allBtn, meetBtn);
|
|
container.insertBefore(newBtn, meetBtn);
|
|
newBtn.style.borderBottom = '5px solid #216ba8';
|
|
|
|
function enableBtn(btn) {
|
|
btn.style.backgroundColor = '#f26833';
|
|
btn.querySelector('a').style.color = 'white';
|
|
}
|
|
function disableBtn(btn) {
|
|
btn.style.backgroundColor = 'white';
|
|
btn.querySelector('a').style.color = '#216ba8';
|
|
}
|
|
|
|
function updateFn() {
|
|
document.querySelectorAll('.menu .user-description + .text-truncate').forEach(function(elem) {
|
|
let text = elem.innerText;
|
|
|
|
if (mode === MODE_ALL) {
|
|
if (text.match(/^Vous:/)) {
|
|
elem.parentNode.parentNode.parentNode.parentNode.style.display = "block";
|
|
}
|
|
}
|
|
if (mode === MODE_NEW) {
|
|
if (text.match(/^Vous:/)) {
|
|
elem.parentNode.parentNode.parentNode.parentNode.style.display = "none";
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function allClick(ev) {
|
|
ev.preventDefault();
|
|
mode = MODE_ALL;
|
|
enableBtn(allBtn);
|
|
disableBtn(newBtn);
|
|
}
|
|
|
|
function newClick(ev) {
|
|
ev.preventDefault();
|
|
mode = MODE_NEW;
|
|
enableBtn(newBtn);
|
|
disableBtn(allBtn);
|
|
}
|
|
|
|
enableBtn(allBtn);
|
|
newBtn.addEventListener('click', newClick);
|
|
allBtn.addEventListener('click', allClick);
|
|
setInterval(updateFn, 500);
|
|
|
|
})();
|