From e48cb3e8b4ed8a0edd53be3224eac66db6edfa4d Mon Sep 17 00:00:00 2001 From: Benjamin Southall Date: Thu, 1 Jun 2017 07:20:30 +0900 Subject: [PATCH] Add support for client side configurable board list aliasing. --- js/boardlist-alias.js | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 js/boardlist-alias.js diff --git a/js/boardlist-alias.js b/js/boardlist-alias.js new file mode 100644 index 00000000..2324e803 --- /dev/null +++ b/js/boardlist-alias.js @@ -0,0 +1,139 @@ +$(document).on("ready", function() { +if (window.Options && Options.get_tab('general')) { + Options.extend_tab("general", + "
Board List Alias " + + ("") + + ("") + + ("") + + ("") + + ("") + + "
"); +} + +$('.boardlist-tinyalias').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); +$('.boardlist-legacyalias').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); +$('.boardlist-unicodealias').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); +$('.boardlist-hideoverboards').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); +$('.boardlist-hideunderboards').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); + +if (!localStorage.boardlisttinyalias) { + localStorage.boardlistshortalias = 'false'; +} +if (!localStorage.boardlistlegacyalias) { + localStorage.boardlistlegacyalias = 'false'; +} +if (!localStorage.boardlistunicodealias) { + localStorage.boardlistunicodealias = 'false'; +} +if (!localStorage.boardlisthideoverboards) { + localStorage.boardlisthideoverboards = 'false'; +} +if (!localStorage.boardlisthideunderboards) { + localStorage.boardlisthideunderboards = 'false'; +} + +function getSetting(key) { + return (localStorage[key] == 'true'); +} + +if (getSetting('boardlisttinyalias')) $('#boardlisttinyalias>input').prop('checked', 'checked'); +if (getSetting('boardlistlegacyalias')) $('#boardlistshortalias>input').prop('checked', 'checked'); +if (getSetting('boardlistunicodealias')) $('#boardlistunicodealias>input').prop('checked', 'checked'); +if (getSetting('boardlisthideoverboards')) $('#boardlisthideoverboards>input').prop('checked', 'checked'); +if (getSetting('boardlisthideunderboards')) $('#boardlisthideunderboards>input').prop('checked', 'checked'); + +function initBoardListAlias() { + + do_boardlist_alias = function() { + var categories = []; + var topbl = $('.boardlist:first'); + + topbl.find('>.sub').each(function() { + var cat = {name: $(this).data('description'), boards: []}; + if (getSetting("boardlisthideoverboards")){ + if (cat.name === "Overboards 1"){ + $(this).hide(); + } + } + if (getSetting("boardlisthideunderboards")){ + if (cat.name === "People"){ + $(this).hide(); + } + + } + $(this).find('a').each(function() { + var board = $(this).html(); + var menuitemname = board; + + var tinyalias = {"$$$" : "$", "rules" : "law" , "faq" : "?" , "news" : "n" , "diy" : "Δ", "sec" : "s", "tech" : "Ω", "inter" : 'i', "lit" : "l", "music" : "mu" , "vis" : "v" , "hum" : "h", "drg" : "d" , "zzz" : "z" , "layer" : "ddt" ,"cult" : "c" , "psy" : "p", "mega" : "me" , "random" : "ra", "radio" : "rad", "stream" : "mov"}; + var legacyalias = { "Δ" : "diy", "Ω" : "tech", "drug" : "drg", "hum" : "feels"}; + var unicodealias = {"$$$": "💸", "rules" : "⚖️" , "faq" : "⁉️" , "news" : "📰" , "diy" : "🔧" , "Δ" : "🔧", "sec" : "🔒", "tech" : "💻", "Ω" : "💻", "inter" : "🎮", "lit" : "✍️", "music" : "🎼" , "vis" : "🎨" , "hum" : "👥", "drg" : "💊" , "drug" : "💊" , "zzz" : "💤" , "layer" : "㊙️" ,"cult" : "🎭" , "psy" : "🎆", "mega" : "📣" , "random" : "🎲", "radio" : "📻", "stream" : "📺", "zine" : "📓", "irc" : "📝", "q" : "❓", "r" : "🎲"}; + + if (getSetting("boardlisttinyalias")) { + if (board in tinyalias){ + menuitemname = tinyalias[board]; + } + } + else if (getSetting("boardlistlegacyalias")){ + if (board in legacyalias){ + menuitemname = legacyalias[board]; + } + + } + else if (getSetting("boardlistunicodealias")){ + if (board in unicodealias){ + menuitemname = unicodealias[board]; + } + } + $(this).html(menuitemname); + }); + do_boardlist_alias = undefined; + + }); + if (typeof twemoji.parse !== 'undefined') { + if (!getSetting("emojiimagefallback")) {return;} + var twemoji_opts = { + callback: function(icon, options, variant) { + switch ( icon ) { + case 'a9': // copyright + case 'ae': // (R) + case '2122': // TM + case '25b6': // post filter + return false; + } + return ''.concat(options.base, options.size, '/', icon, options.ext); + } + } + twemoji.parse(document.body, twemoji_opts); + } + } + do_boardlist_alias(); +} +initBoardListAlias(); +}); +