Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitecc5a0518224259b89019da7b509b3811148109d (patch)
Author
 Kamen Mladenov <kamen@syndamia.com>
2023-03-18 12:18:53 +0000
Committer
 Kamen Mladenov <kamen@syndamia.com>
2023-03-18 12:18:53 +0000
Filesfc4fb32912a20f03b0ad15273af812d0741bf0d4
userscripts-ecc5a0518224259b89019da7b509b3811148109d.tar
userscripts-ecc5a0518224259b89019da7b509b3811148109d.tar.gz
userscripts-ecc5a0518224259b89019da7b509b3811148109d.zip
Parentb9fcf0cd9d3c70941150505145f57a43a3dda375 (diff)
[vfk/v1.4] Moved illegitimate solutions to the bottom of a sorted solutions page and added comments
1 files changed, 33 insertions, 4 deletions
-rw-r--r--vim-fmi-keystrokes.js37
diff --git a/vim-fmi-keystrokes.js b/vim-fmi-keystrokes.js
index 212698d..bd754d7 100644
--- a/vim-fmi-keystrokes.js
+++ b/vim-fmi-keystrokes.js
@@ -2,7 +2,7 @@
// @name vim-fmi точки
// @description Добавя брой натиснати клавиши във всяка страница на решения
//
-// @version 1.3
+// @version 1.4
// @license MIT
// @author Syndamia
//
@@ -17,6 +17,7 @@
// ==/UserScript==
if (window.location.pathname.endsWith('solutions')) {
+ /* Add scores for each solution */
document.getElementsByTagName('tbody')[0].childNodes.forEach((x) => {
if (x.tagName != 'TR') return;
var countElem = document.createElement('div');
@@ -26,22 +27,50 @@ if (window.location.pathname.endsWith('solutions')) {
x.children[1].insertBefore(countElem, x.children[1].firstChild);
});
+ /* Sorting */
var sortBtn = document.createElement('div');
sortBtn.classList.add('action');
sortBtn.innerText = 'Сортирай по решения';
document.getElementsByClassName('main')[0].children[2].appendChild(sortBtn);
+ function getScore(elem) {
+ return (elem) ? parseInt(elem.children[1].children[0].innerText) : '';
+ }
+ function getSolution(elem) {
+ return (elem) ? elem.children[1].children[1].innerText : '';
+ }
+ function getDate(elem) {
+ return (elem) ? elem.children[2].innerText : '';
+ }
+
sortBtn.addEventListener('click', function () {
var rows = [...document.getElementsByClassName('solutions')[0].children[1].children];
rows.sort(function (a, b) {
- var aInt = parseInt(a.children[1].children[0].innerText);
- var bInt = parseInt(b.children[1].children[0].innerText);
- return aInt > bInt || (aInt == bInt && a.children[2].innerText > b.children[2].innerText);
+ var aInt = getScore(a), bInt = getScore(b);
+ return aInt > bInt || (aInt == bInt && getDate(a) > getDate(b));
});
+
+ /* Every following solution that is the same as the current one, or
+ * if a solution pastes content from the system clipboard, or
+ * if a solution uses the read command,
+ * it is deemed to be "cheated", and is put at the bottom of the list */
+ for (var i = rows.length - 1; i >= 0; i--) {
+ if ((getScore(rows[i]) == getScore(rows[i-1]) && getSolution(rows[i]) == getSolution(rows[i-1]))
+ || getSolution(rows[i]).match(/("[+*](|[gz\[\]])(p|P|<MiddleMouse>)|:pu[ t]|:r( |ead))/))
+ {
+ var cheated = rows.splice(i, 1)[0];
+ cheated.style.textDecoration = 'line-through';
+ cheated.style.fontStyle = 'italic';
+ cheated.style.opacity = '0.5';
+ rows.push(cheated);
+ }
+ }
+
document.getElementsByClassName('solutions')[0].children[1].replaceChildren(...rows);
});
}
else {
+ /* Add scores for each solution */
document.getElementsByTagName('ul')[3].childNodes.forEach((x) => {
if (x.tagName != 'LI') return;
var countElem = document.createElement('span');