NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name metadev-favorites-ext // @namespace https://openuserjs.org/users/mchdev // @description adds favorites submenu to metarepository's side menu // @homepageURL https://openuserjs.org/scripts/mchdev/metadev-favorites-ext // @updateURL https://openuserjs.org/meta/mchdev/metadev-favorites-ext.meta.js // @downloadURL https://openuserjs.org/install/mchdev/metadev-favorites-ext.user.js // @copyright 2021, mchdev (https://openuserjs.org/users/mchdev) // @license MIT // @version 0.3 // @grant GM_addStyle // @author mchdev // @match https://meta.vub.sk/* // @match https://meta2.vub.sk/* // ==/UserScript== (function () { 'use strict'; GM_addStyle('.sidemenu-favs ul.side-menu-sub { margin-left: 5px !important; }'); GM_addStyle('.sidemenu-favs div.smenutext { margin-left: 5px !important; }'); const KEY = 'metadev-favorites-ext'; $(document).on('loaded-ALLBOXES', () => { const group = $('ul.tabmenu > li:first > a:first').text().replace(':', ''); const anchor = $('ul.tabmenu > li:first > a:last').get(0); const href = anchor.href; const title = anchor.title; if (group && href && title) { const favs = JSON.parse(localStorage.getItem(KEY) || '{}'); const found = (favs[group] || []).find(e => e.href == href && e.title == title); const el = found ? $('<a title="remove from favorites" class="fav-star">⭐</a>').click(() => { let favs = JSON.parse(localStorage.getItem(KEY) || '{}'); favs[group] = (favs[group] || []).filter(e => e.href != href || e.title != title); !favs[group].length && delete favs[group]; localStorage.setItem(KEY, JSON.stringify(favs)); location.reload(); }) : $('<a title="add to favorites" class="fav-star">👀</a>').click(() => { let favs = JSON.parse(localStorage.getItem(KEY) || '{}'); favs[group] = favs[group] || []; favs[group].push({ href, title }); localStorage.setItem(KEY, JSON.stringify(favs)); location.reload(); }); $('ul.tabmenu > li:first').prepend(el); } }); $('ul.side-menu').prepend($('<li class="sidemenu-favs"><div class="upmenu collapsed" id="up-menu-favorites" data-togleid="favorites"></div><div class="menutext menutextup" data-togleid="favorites">Favorites</div><ul class="side-menu-sub" id="sub-menu-favorites" style="display:none"></ul></li>')); const favs = JSON.parse(localStorage.getItem(KEY) || '{}'); for (const group in favs) { const _group = group.replace(/\s+/g, ''); $('#sub-menu-favorites').append(`<li><div class="upmenu collapsed" id="up-menu-fav-${_group}" data-togleid="fav-${_group}"></div><div class="menutext menutextup" data-togleid="fav-${_group}">${group}</div><ul class="side-menu-sub" id="sub-menu-fav-${_group}" style="display:none"></ul></li>`); favs[group].forEach(entity => { $(`#sub-menu-fav-${_group}`).append(`<li><div class="smenutext"><a href="${entity.href}" title="${entity.title}">${entity.title}</a></div></li>`); }); } })();