Skip to content

Commit

Permalink
Implement shift click batch checked (mangadex)
Browse files Browse the repository at this point in the history
  • Loading branch information
asl97 committed Sep 11, 2019
1 parent 26322da commit f623885
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mm/dd/yy

9/4/19
Implement shift click batch checked (mangadex)

8/6/19
Fix ordering of page via prefix (mangastream)

Expand Down
2 changes: 1 addition & 1 deletion dist/mangadex.menu.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions src/mangadex.menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bookmarklet([
});
}

var chapters, langs, checkboxes, chapter_content, bg_div;
var chapters, langs, checkboxes, last_checkbox, chapter_content, bg_div;
langs = {};
chapters = {};
checkboxes = {};
Expand Down Expand Up @@ -192,6 +192,24 @@ bookmarklet([
process_dl_tasks(dl_list);
}

function multi_select_checkbox_handler(checkbox, event){
if (event.shiftKey && last_checkbox){
let start, stop;
[start, stop] = [checkbox.dataset.id, last_checkbox.dataset.id].sort();
for (let el of Object.values(checkboxes)){
if (el.parentElement.style.display === 'none'){
continue;
};
if (start <= el.dataset.id && el.dataset.id <= stop){
el.checked = last_checkbox.checked;
}
}
} else {
checkbox.checked = !checkbox.checked;
}
last_checkbox = checkbox;
}

function el_checkbox(chapter_obj){
var div, title, lang, checkbox, lang_code, name, group_name;

Expand Down Expand Up @@ -229,16 +247,20 @@ bookmarklet([
checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.style.display = "table-cell";
checkbox.dataset.id = chapter_obj.chapter_id;
checkbox.onclick = (e)=>{
// HACK: undo default checkbox checking
// multi_select_checkbox_handler handles checkbox.checked
checkbox.checked = !checkbox.checked;
};

checkboxes[chapter_obj.chapter_id] = checkbox;

div.appendChild(checkbox);

// make clicking on the 'row' the same as clicking on the checkbox
// makes it less of a pain to click
title.onclick = function(){checkbox.click()};
lang.onclick = function(){checkbox.click()};

div.onclick = (e)=>{multi_select_checkbox_handler(checkbox, e)};
return div
}

Expand All @@ -247,7 +269,7 @@ bookmarklet([
if (lang_code == "All" || lang_code == el.dataset.lang_code){
el.style.display = "table-row";
} else {
el.style.display = "None";
el.style.display = "none";
}
}
}
Expand Down

0 comments on commit f623885

Please sign in to comment.