Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- _ _ _ _ _
- | | | | | | | | | |
- | | | |_ _| | | |_ __ __ _ _ __ __ _ __| | ___
- | | | \ \ /\ / / | | | '_ \ / _` | '__/ _` |/ _` |/ _ \
- | |__| |\ V V /| |__| | |_) | (_| | | | (_| | (_| | __/
- \____/ \_/\_/ \____/| .__/ \__, |_| \__,_|\__,_|\___|
- | | __/ |
- |_| |___/
- */
- //version 1.2.0
- //Quality of life scripts for 8ch/kun
- function uwupgrade_board()
- {
- var boards = [
- //"ALL!", //uncomment for use on all boards
- "fur",
- "furry",
- "test",
- ]
- configure_post_form(boards);
- enable_spoiler_settings(boards);
- }
- function on_ready(fn)
- {
- if (document.readyState == 'loading') {
- window.addEventListener('DOMContentLoaded', fn);
- }
- else {
- fn();
- }
- }
- on_ready(uwupgrade_board);
- function valid_board(list)
- {
- for (var i = 0; i < list.length; i++) {
- if(list[i] === window.board_name || list[i] === "ALL!"){
- return true;
- }
- }
- return false;
- }
- function url_contains(string)
- {
- return (window.location.href.indexOf(string) > -1) ? true : false;
- }
- /*
- ___ _ ___
- | _ \___ __| |_ | __|__ _ _ _ __
- | _/ _ (_-< _| | _/ _ \ '_| ' \
- |_| \___/__/\__| |_|\___/_| |_|_|_|
- */
- function configure_post_form(boards, active=true)
- {
- function get_row(table, name)
- {
- var list = table.getElementsByTagName("th");
- for (var i = 0; i < list.length; i++)
- {
- if (list[i].innerHTML.indexOf(name) > -1){
- return email = list[i].parentElement;
- }
- }
- return null;
- }
- function hide_email()
- {
- var mainTable = document.getElementsByClassName("post-table")[0];
- var email = get_row(mainTable, "Email");
- email.style.display = "none";
- }
- function move_password()
- {
- var mainTable = document.getElementsByClassName("post-table")[0];
- var subTable = document.getElementsByClassName("post-table-options")[0];
- var password = get_row(mainTable, "Password");
- var other = get_row(subTable, "Other");
- subTable.childNodes[0].insertBefore(password, subTable.childNodes[0].childNodes[0]);
- }
- function rename_options()
- {
- var subTable = document.getElementsByClassName("post-table-options")[0];
- var other = get_row(subTable, "Options");
- other.getElementsByTagName("th")[0].innerHTML = "Other";
- }
- function rename_archive()
- {
- var mainTable = document.getElementsByClassName("post-table")[0];
- var options = get_row(mainTable, "Archive");
- options.getElementsByTagName("th")[0].innerHTML = "Options";
- }
- function create_option()
- {
- var mainTable = document.getElementsByClassName("post-table")[0];
- var row = document.createElement("TR");
- var header = document.createElement("TH");
- var data = document.createElement("TD");
- header.innerHTML = "Options"
- row.appendChild(header);
- row.appendChild(data);
- mainTable.childNodes[0].insertBefore(row, mainTable.childNodes[0].childNodes[5]);
- }
- function option_settings()
- {
- var mainTable = document.getElementsByClassName("post-table")[0];
- var options = get_row(mainTable, "Options");
- var data = options.getElementsByTagName("td")[0];
- //create anchor/sage option
- var anchor = document.createElement("INPUT");
- anchor.title = "Don't bump";
- anchor.id = "no-bump";
- anchor.name = "no-bump";
- anchor.type = "checkbox"
- var anchorLabel = document.createElement("LABEL");
- anchorLabel.appendChild(anchor);
- anchorLabel.innerHTML += "Anchor post";
- //create spoiler option
- var spoiler = document.createElement("INPUT");
- spoiler.title = "Hide file thumbnails with a spoiler";
- spoiler.id = "spoiler";
- spoiler.name = "spoiler";
- spoiler.type = "checkbox"
- var spoilerLabel = document.createElement("LABEL");
- spoilerLabel.appendChild(spoiler);
- spoilerLabel.innerHTML += "Spoiler all files";
- //append options
- data.innerHTML = ""
- data.appendChild(spoilerLabel);
- data.appendChild(anchorLabel);
- }
- function other_settings()
- {
- var subTable = document.getElementsByClassName("post-table-options")[0];
- var other = get_row(subTable, "Other");
- var data = other.getElementsByTagName("td")[0];
- //remove extra
- var oldAnchor = data.getElementsByClassName("no-bump-option")[0];
- data.removeChild(oldAnchor);
- }
- if(!valid_board(boards))
- return;
- if(!url_contains("catalog")) //thread
- {
- hide_email();
- move_password();
- rename_options();
- rename_archive();
- option_settings();
- other_settings();
- }
- else //catalog
- {
- hide_email();
- rename_options();
- create_option();
- option_settings();
- other_settings();
- }
- }
- /*
- ___ _ _ ___ _ _
- / __|_ __ ___(_) |___ _ _ / __|___ _ _| |_ _ _ ___| |
- \__ \ '_ \/ _ \ | / -_) '_| | (__/ _ \ ' \ _| '_/ _ \ |
- |___/ .__/\___/_|_\___|_| \___\___/_||_\__|_| \___/_|
- |_|
- */
- //Adapted from marktaiwan => https://github.com/marktaiwan/8kun-disable-spoiler-thumbnail
- //It's not feasible to unspoiler images in catalog
- function enable_spoiler_settings(boards)
- {
- function unspoiler(postImage)
- {
- if( postImage.src.endsWith(`/static/assets/${window.board_name}/spoiler.png`) ||
- postImage.src.endsWith('/static/spoiler.png'))
- {
- //❔
- const fileURL = postImage.closest('div.file').querySelector('.fileinfo>a[title]').href;
- if (fileURL === undefined || fileURL.indexOf('/file_store/') == -1) return;
- const spoilerImg = postImage.src;
- const thumbURL = fileURL.replace('/file_store/', '$&thumb/').replace((/(webm|mp4)$/), 'jpg');
- postImage.onerror = () => postImage.src = spoilerImg;
- postImage.onload = () => {
- const multifile = postImage.closest('.multifile');
- postImage.style.width = `${postImage.naturalWidth}px`;
- postImage.style.height = `${postImage.naturalHeight}px`;
- if (multifile) {
- multifile.style.width = `${postImage.naturalWidth + 40}px`;
- }
- //set indicator - so you know a file was successfully spoilered
- const span = postImage.closest('div.file').querySelector('.fileinfo>span');
- span.innerHTML = "❓" + span.innerHTML;
- };
- postImage.src = thumbURL;
- }
- }
- function enable_general_setting()
- {
- //create state for setting if needed
- if(localStorage.disable_image_spoiler === undefined) {
- localStorage.disable_image_spoiler = 'false';
- }
- //create setting html
- var setting = document.createElement("INPUT");
- setting.id = "disable-spoiler";
- setting.type = "checkbox"
- var settingLabel = document.createElement("LABEL");
- settingLabel.appendChild(setting);
- settingLabel.innerHTML += "Remove file spoilers (extension)";
- //extend general options with setting
- window.Options.extend_tab("general", settingLabel.outerHTML);
- //add toggle logic to setting
- document.querySelector("#disable-spoiler").addEventListener('change', () => {
- result = (localStorage.disable_image_spoiler === 'true') ? 'false' : 'true';
- localStorage.disable_image_spoiler = result;
- });
- if(localStorage.disable_image_spoiler === 'true') {
- document.querySelector('#disable-spoiler').setAttribute('checked', true);
- }
- }
- function unspoiler_page()
- {
- document.querySelectorAll('.post-image').forEach(unspoiler);
- //jQuery(document).on('new_post', function (e, post) {
- //post.querySelectorAll('.post-image').forEach(unspoiler);
- //});
- document.addEventListener('new_post', function (e, post){
- post.querySelectorAll('.post-image').forEach(unspoiler);
- });
- }
- function enable_thread_setting()
- {
- //create state for setting if needed
- if(sessionStorage.disable_image_spoiler === undefined){
- sessionStorage.disable_image_spoiler = 'false';
- }
- //create setting html
- var setting = document.createElement("A");
- setting.className = "unimportant";
- setting.href = "javascript:void(0)";
- setting.innerHTML = (sessionStorage.disable_image_spoiler === 'false') ?
- 'Reveal Spoilers' : 'Restore Spoilers';
- var container = document.createElement("DIV");
- container.id = "reveal-spoilers";
- container.appendChild(setting);
- var body = document.getElementsByClassName("8kun")[0];
- var target = document.getElementById("expand-all-images")
- body.insertBefore(container, target.nextSibling.nextSibling);
- container.childNodes[0].addEventListener('click', function(e) {
- if(sessionStorage.disable_image_spoiler === 'false'){
- sessionStorage.disable_image_spoiler = 'true';
- e.target.innerHTML = 'Restore Spoilers'
- unspoiler_page();
- }
- else{
- sessionStorage.disable_image_spoiler = 'false';
- e.target.innerHTML = '♻️page(click to undo)'
- }
- })
- }
- if(!valid_board(boards))
- return;
- enable_general_setting();
- if(localStorage.disable_image_spoiler === 'true'){
- //remove spoilers
- if( window.active_page === 'thread' ||
- window.active_page === 'index'){
- unspoiler_page();
- }
- }
- else
- {
- if( window.active_page === 'thread'){
- enable_thread_setting();
- }
- //var thread = document.getElementsByClassName("post_anchor")[0].id;
- if( sessionStorage.disable_image_spoiler === 'true'){
- unspoiler_page();
- }
- }
- }
- /*
- ___ _
- | __|_ _ __| |
- | _|| ' \/ _` |
- |___|_||_\__,_|
- */
Add Comment
Please, Sign In to add comment