Skip to content

Instantly share code, notes, and snippets.

@UCyborg
Last active August 6, 2025 20:09
Show Gist options
  • Select an option

  • Save UCyborg/ed57c4681f2ecc503a17488f0a1f9d07 to your computer and use it in GitHub Desktop.

Select an option

Save UCyborg/ed57c4681f2ecc503a17488f0a1f9d07 to your computer and use it in GitHub Desktop.
Smart preview for Pale Moon forum
// ==UserScript==
// @name Smart preview for Pale Moon forum
// @namespace https://github.com/UCyborg
// @description User script version of XUL bootstrapped extension of the same name by JustOff
// @version 1.0
// @author UCyborg
// @downloadURL https://gist.github.com/UCyborg/ed57c4681f2ecc503a17488f0a1f9d07/raw/Smart_preview_for_Pale_Moon_forum.user.js
// @match https://forum.palemoon.org/*
// @run-at document-start
// @require https://code.jquery.com/jquery-3.7.1.slim.min.js
// @grant GM_addStyle
// ==/UserScript==
'use strict';
GM_addStyle(`
.topics .list-inner, .pmlist .list-inner, .lastpost > span, .search.post > .inner,
.notification-block > .notification_text, .notifications, #iou-list a {
cursor: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAjVBMVEUAAABSmeJNk+BNlOBSmOJaouZRmeJYoOVIjt5cpOZqsutVmuVWnOZDidtZoeVIjt5bouZOleBVneNFi9xcpOZFi9xHjd1Mk99Fi9xcpOZXn+RCiNtDiNtpsetqsetAhdpfpOx5wvJlqu50u+9ute4Wb9QabM4daMl5vPpboOgdfN1Fi9wbddYhZcMkY775jfcHAAAAIHRSTlMABg1R+BoSVRj58/Pr2dPTz8fDwsGxeW5ubGxO+e3rCMgm9vgAAACXSURBVBjTbY1XDoMwEEQXG5veO2lgg02///GS2EHiI0/aj3k70sA/jCZ3nLwxzkziXhGT3z/sXYsQy+1D3Wn5g8I4An3yVomUW/AVgHmqhDkgIZZFCDSYp5By26Q8RcIwwL4DYJYoUTGfwnEA9VmlZyPmYdvGHmMlKOyo00xdgXSnztY1q8t56gIDLhTz/QZXUKDyhdfn3mO4DAI3GV+/AAAAAElFTkSuQmCC') 5 5, zoom-in;
}
.rclickview {
cursor: alias;
}
#previewdiv {
z-index: 20;
position: fixed;
left: 15%;
top: 15%;
width: 85%;
height: 85%;
transform: translate(-9%,-9%);
background-color: rgba(212,208,200,.4);
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANwAAAAyCAMAAAAAykVBAAAAbFBMVEUAAAD29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vbV1dX29vacnJzDw8P4+PjKysry8vK9vb3Y2NixsbHo6Ojc3NzOzs7i4uLQ0NDu7u6mpqa4uLiqqqrs7OxhJpsjAAAAEHRSTlMAQH+/EO/PUDAgr2CP359wBUJ9wQAAA0BJREFUaN7slt2OhCAMhaVQQH405/1fdmlhYtzETeZqccZzUVtakn4hBZdHjx49evTo0XfK0Ppm7UpmuYkI5s1aA1puojfhPv3kbqRfDQei+PLXTBSORHa91pl12EC7e9XubZ+Jy1w6wTmPpq0HO0TeacKKW14zp7ZIMXeerPtgl7l0gvNIJngU8Q04S0ASbC2RGSc49sEkJD038G42TA0XtFVX4ZTHaNtWllCbjWe46lqCIRsLcrNparjSfYJOmvoOVql3CewJbutLYj2LjVPDaafHQxYoecAeRXSCo2PLoLoPnF4unD4IzvXRI52gZFo44MKfcOzFuqnhCOEYPfhjjgyKBP4KLmFtNk8NF+Fds8xO4Kq+b71h5ig8V3BZrtm1TgjnrSrq9V+pMLKehviV+wEGcCmoF3DyqZZ5wGGUoWdo+TcRhoxEBQAL2/gpseuYw8zARpdwbmPYOB3cT/tlt5wgDERh2+pUe2NwTTb8hJ/2/d+x2Q0awjKZsfaiQzl448c5C0cyTJxp/zJZpS+nyYncxvG4Z4tfnCvU2/hCOe9WqHPh95mvh8Npt0Z9FF6H9906dXz1//d2mzZtWoewv6xGPc66DWVZotfQf5ZBPQILBQECKcl4niNycv5aOFCJtF2PJeqmVQqHcB4GVEpZLyiRKgIRayMBFARwQthBKTshck6ANp8CFASQibyfVje2T8pdSlC1c1U9aN34QwO6isSEQCSORjG6e5gQih49xpIUs5Skkyky9dTCU9Nkca1m4nGuvaTlUNV0AqBVdCisDasjwgqkMyYhBIyvalOSTzGSJM7JXF144pyYmpXTdeWxBaUsfXRTBNWgGCWEQUqYyVTeE1CeBJQnQZGIcu7LFN3NZ8E3vXox4SoYyYiAvzMhzYkVhJlMYXYOxxYny/thQi2Wyt2euAVXsJiwFkhYBAm5eQKSJD9HevTYJHst7pZOXig3f8DXq/t1oq8kSWTqGY8sV+F8WRh+vZCwG6P3WdETwKJnJJ30xMnCc09lPOIO2wmZl+utrTQosVCUXARBmPNI8sjkHxJjIulnOxSn8PYjaPEeypF7ykQyeoz0PJCKC+CBFBPE/7O33LTpL+kbdjLoImriSOcAAAAASUVORK5CYII=');
background-position: center;
background-repeat: no-repeat;
display: none;
}
#previewframe {
width: 100%;
height: 100%;
border: 2px groove;
}
#closediv {
z-index: 10;
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background: rgba(0,0,0,.2);
display: none;
}
#newtabdiv {
z-index: 15;
position: fixed;
right: 0px;
top: 0px;
width: 6%;
height: 6%;
border-left: 1px solid;
border-bottom: 1px solid;
background: rgba(89,179,255,0.3);
display: none;
}
#iou-list {
float: right;
font-size: 11px;
font-family: Verdana,Helvetica,Arial,sans-serif;
padding-right: 2px;
overflow: hidden;
max-width: 60%;
max-height: 48px;
}
#iou-list a:hover {
text-decoration: none;
background-color: WhiteSmoke;
}
#iou-head {
float: left;
height: 48px;
margin-right: 5px;
}
.hg-wsnowrap{
font-style: italic;
white-space: nowrap;
}
#site-description > h1 {
margin-top: 10px;
}
#site-description > p {
margin-bottom: 1px;
}
h2.posting-title {
overflow: auto;
}
#page-body div:first-of-type {
min-height: 16px;
}
#page-body .rules {
height: 1.2em;
overflow: hidden;
width: min-content;
}
#page-body .rules:hover {
height: auto;
width: auto;
}
`);
var linkObj, isCtrlDown = false;
function hide_preview(e) {
if (e && e.data.key == "newtab") {
window.open($('#previewframe').attr('src'), '_blank');
}
$('#previewframe').remove();
$('#closediv, #newtabdiv, #previewdiv').hide();
linkObj && linkObj.parents('dl[class*="_read"], dl[class*="_unread"]').filter(function() {
var that = this;
setTimeout(function() {
$(that).css("background-color", "");
}, 700);
if (this.className.match(/item .+?_unread/)
&& (linkObj.prop("href").indexOf("#") != -1 || linkObj.attr("class") == "topictitle")) {
this.className = this.className.replace("_unread", "_read");
$(this).children("dt").attr("title", "There are no new unread posts for this topic.");
return true;
}
}).find('a[href*="view=unread#unread"]').remove();
linkObj = null;
}
function show_iframe(href) {
$('#previewdiv').append($('<iframe>', {id: "previewframe", src: href}));
$('#previewdiv, #closediv, #newtabdiv').show();
$('#previewframe').on("load", function(){
$(this).contents().find("head").append('<style>#page-header, #page-footer {display: none;} html {height: 100%;} body.section-viewonline th.active {width: 20%;} #page-body .rules {height: 1.2em; overflow: hidden; width: -moz-min-content;} #page-body .rules:hover {height: auto; width: auto;}</style>');
$(document.getElementById("previewframe").contentWindow.document).on("keydown", function(e) {
if (e.key == "Escape"){
el = document.getElementById("previewframe").contentWindow.document.activeElement.tagName;
if (el != "INPUT" && el != "TEXTAREA") {
hide_preview();
}
}
});
});
}
function show_preview(e) {
var el = document.elementFromPoint(e.clientX, e.clientY);
if (e.data.key == '.topictitle' || e.data.key == 'a[href*="&p="]') {
if (!el.classList.contains("list-inner") && el.parentElement.className != "lastpost") {
return;
}
$(this).parents('dl[class*="_read"], dl[class*="_unread"]').each(function() {
var href;
$(this).css("background-color", "LightSteelBlue");
$(this).find(e.data.key).each(function() {
if (!this.title || this.title != "Topic is solved") {
href = this.href;
linkObj = $(this);
return false;
}
});
if (href && href.indexOf("#") == -1 && this.className.match(/item .+?_unread/)) {
href += "&view=unread#unread";
}
show_iframe(href);
return false;
});
} else if (e.data.key == 'search') {
if (el.tagName == "A" || $(el).parents('a').length) {
return;
}
$(this).find('a[href*="&p="]').each(function() {
linkObj = $(this);
show_iframe(this.href);
return false;
});
} else if (e.data.key == 'notification') {
var href;
if (this.parentNode.tagName == "A") {
linkObj = $(this.parentNode);
href = this.parentNode.href;
} else if (this.firstElementChild.tagName == "A") {
if ($(el).parents('a').length) {
return;
}
linkObj = $(this.firstElementChild);
href = this.firstElementChild.href;
} else {
return;
}
show_iframe(href);
} else if (e.data.key == 'href-context') {
if (e.ctrlKey && is_pmforum.call(this)) {
linkObj = $(this);
show_iframe(this.href);
} else {
return;
}
} else if (e.data.key == 'href-normal') {
if (!e.ctrlKey && !e.shiftKey && is_pmforum.call(this)) {
linkObj = $(this);
show_iframe(this.href);
} else {
return;
}
}
return false;
}
function is_pmforum() {
return this.href.match(/forum\.palemoon\.org/)
&& this.href.split("#")[0] != window.location.href.split("#")[0];
}
function handle_key(e) {
if (e.data.key == "down") {
if (e.ctrlKey && !isCtrlDown) {
isCtrlDown = true;
$("a").filter(is_pmforum).toggleClass("rclickview", true);
} else if (e.key == "Escape") {
hide_preview();
}
} else {
if (isCtrlDown) {
isCtrlDown = false;
$("a").filter(is_pmforum).toggleClass("rclickview", false);
}
}
}
function who_online() {
$("#iou-list").remove();
var request = new XMLHttpRequest(/* {mozAnon: true} */);
request.open("GET", "https://forum.palemoon.org/index.php");
request.responseType = "document";
request.onload = function() {
var span = $('<span id="iou-list"><span id="iou-head"><a href="./viewonline.php">Online users</a>:</span></span>');
var ulist = "";
var olist = $(this.responseXML).find('.online-list');
olist.find('.username, .username-coloured').each(function() {
if (this.style.color != "rgb(170, 119, 119)" && this.firstChild.nodeName != "EM") {
span.append(this).append(document.createTextNode(', '));
ulist += this.textContent + ", ";
}
});
olist.find('p').each(function() {
var hg = this.textContent.match(/(\d+ hidden) and (\d+ guests)/);
if (hg) {
span.append($('<span class="hg-wsnowrap">' + hg[1] + '</span>'));
span.append(document.createTextNode(', '));
span.append($('<span class="hg-wsnowrap">' + hg[2] + '</span>'));
ulist += hg[1] + ", " + hg[2];
}
return false;
});
$("#page-body > h2").append(span);
$("#iou-head").attr("title", ulist);
$("#iou-head").on("click", who_online);
$("#iou-list a").on("click", {key: 'href-normal'}, show_preview);
}
request.send();
}
$(document).ready(function() {
$('#nav-breadcrumbs').append('<li class="rightside"><a href="./search.php?search_id=unanswered" role="menuitem"><i class="icon fa-file-o fa-fw icon-gray" aria-hidden="true"></i><span>Unanswered posts</span></a></li><li class="rightside"><a href="./search.php?search_id=active_topics" role="menuitem"><i class="icon fa-file-o fa-fw icon-gray" aria-hidden="true"></i><span>Active topics</span></a></li>');
$('#site-description > p:first-of-type').append('<span class="smart-preview"><br>Explore <a href="https://addons.palemoon.org/extensions/" target="_blank" style="color:yellow;">Extensions</a> and <a href="https://addons.palemoon.org/themes/" target="_blank" style="color:yellow;">Themes</a></span>');
$('body').append($('<div>', {id: "previewdiv"}), $('<div>', {id: "closediv"}), $('<div>', {id: "newtabdiv"}));
$('#closediv').on("click", {key: 'close'}, hide_preview);
$('#newtabdiv').on("click", {key: 'newtab'}, hide_preview);
$(".topics .list-inner, .pmlist .list-inner").on("click", {key: '.topictitle'}, show_preview);
$(".lastpost > span").on("click", {key: 'a[href*="&p="]'}, show_preview);
$(".search.post > .inner").on("click", {key: 'search'}, show_preview);
$(".notification-block > .notification_text, .notifications").on("click", {key: 'notification'}, show_preview);
$("a").on("contextmenu", {key: 'href-context'}, show_preview);
$(document).on("keydown", {key: 'down'}, handle_key);
$(document).on("keyup", {key: 'up'}, handle_key);
if ($("#username_logged_in").length && $("#page-body > h2").length && window.location.href.indexOf("viewonline.php") == -1) {
who_online();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment