File: 6946a4d4a0047d8614857fb32b5b7683749ff3ac4f8ba21a7b4c8ecaddd51d02.png (dl) (782.25 KiB)
/meta/ - Board Meta
[Make a Post]Here's a userscript that replaces the displayed datetext with the datetime value instead because I prefer the format of it. It could probably be formatted better but this is good enough. Should be fairly simple to understand!
// UserScript
// @name nanochanDateChange
// @namespace nanochanUserScript
// @version 0.1
// @description Formats all <time> elements to have the Date the same as its datetime attribute. IE Formats to Year-Month-Day Hour:Minute:SS
// @author Anonymous
// @match http://nanochanxv2lxnqi.onion/nano/*
// @grant none
// /UserScript
(function() {
'use strict';
var timeTags = document.getElementsByTagName("time");
for(var i = 0; i < timeTags.length; i++)
{
timeTags.item(i).innerHTML = timeTags.item(i).getAttribute("datetime");
}
})();
And another to remove the modlinks since they're not really usable to me.
// UserScript
// @name nanochanRemoveModLinks
// @namespace nanochanUserScript
// @version 0.1
// @description Removes list of mod buttons since they're not usable to me anyway.
// @author Anonymous
// @match http://nanochanxv2lxnqi.onion/nano/*
// @grant none
// /UserScript
(function() {
'use strict';
var modLinks = document.getElementsByClassName("thread-mod-links");
while(modLinks[0]) {
modLinks[0].parentNode.removeChild(modLinks[0]);
}
})();
May be a good idea to implement [code] blocks too or allow for uploading user.js files directly.
File: dded66842d458b49aeaacc1de7f6785f57e308c4b444d7edf63566b08f0350d2.png (dl) (25.42 KiB)
>>404
From https://greasyfork.org/en :
"To use user scripts you need to first install a user script manager. Which user script manager you can use depends on which browser you use.
Chrome: Tampermonkey or Violentmonkey
Firefox: Greasemonkey, Tampermonkey, or Violentmonkey
Safari: Tampermonkey
Microsoft Edge: Tampermonkey
Opera: Tampermonkey or Violentmonkey
Maxthon: Violentmonkey
Dolphin: Tampermonkey
UC: Tampermonkey
Qupzilla: (no additional software required)
AdGuard: (no additional software required)"
A dumb little script I made to learn javascript, and to have an excuse to bump this thread for interest
The GM_addStyle line needs to be removed if using anything but tampermonkey, since I can't find any other fucking way to use css in a userscript on firecucks (crazy cors restrictions) and a heavily csp-restricted site like this one.
Remove the ~'s in between the two equals "=~="
// =~=UserScript=~=
// @name visiblesage-nanochan
// @namespace nanochanUserScript
// @version 0.1
// @description Adds a useless sage indicator to posts
// @author (You)
// @match http://nanochanxv2lxnqi.onion/*
// @grant GM_addStyle
// =~=/UserScript=~=
(function() {
'use strict';
var x = document.getElementsByClassName('post-email');
GM_addStyle('div.post>div.post-header>span.post-sageindicator{color:#c00}');
// GM_addStyle('div.post>div.post-header>span.post-sageindicator{color:#c00;font-weight:bold}');
for (var i = 0; i < x.length; i++) {
if (x[i].href.match('mailto:sage') != null) {
var el = document.createElement('span');
el.classList.add('post-sageindicator');
el.textContent = 'sage!';
var ws = document.createTextNode('\u00A0');
var y = x[i].parentElement.parentElement;
var z = x[i].closest('div.post-header').getElementsByClassName('post-date')[0];
y.insertBefore(el, z);
y.insertBefore(ws, z);
}
}
})();
>>1299
>using javashit for that
you can use pure CSS you know something like
a[href="mailto:sage"]::after {
content: " SAGE!";
color: red;
font-weight: bold;
}
(didn't try it but it's certainly possible in principle)
>>1308
>mfw I became the pajeet
Damn, that seems pretty obvious in hindsight. In my defense I had almost no idea how webdev works before writing that script
Hakase, can you change the date reporting to the d/m/y format instead of the web 2.0 "x time ago?"
It gives me bad twitter flashbacks
>>1329
This will be done soon (in sakamoto) due to technical reasons, anyway. No choice since sakamoto is a static generator (this will allow for significantly reduced page load times).
Since nanochan is going static, and I need relative time, I figured I might as well add quote-on-click.
Remove the ~s.
// =~=UserScript=~=
// @name nanochan usability
// @namespace nanochan-usability
// @version 0.1
// @description Random usability improvements
// @author Anonymous
// @match http://nanochanxv2lxnqi.onion/*
// =~=/UserScript=~=
// Change this to true to keep mod tools
const is_moderator = false;
const rtf = new Intl.RelativeTimeFormat('en', {numeric: 'auto'});
function relativeTime(post) {
let date = post.querySelector('.post-date');
let time = new Date(date.querySelector('time').dateTime);
let difference = new Date() - time;
difference /= 1000;
let unit = 'second';
if(difference > 60) {
unit = 'minute';
difference /= 60;
}
if(difference > 60) {
unit = 'hour';
difference /= 60;
}
if(difference > 24) {
unit = 'day';
difference /= 24;
}
if(difference > 7) {
unit = 'week';
difference /= 7;
}
difference = Math.floor(difference);
date.innerHTML = rtf.format(-difference, unit);
console.log(rtf.format(-difference, unit));
}
function removeModTools(post) {
post.querySelector('.thread-mod-links').innerHTML = '';
}
function autoQuote(post) {
let number = post.querySelector('.post-number a');
number.addEventListener('click', () => {
let reply = document.querySelector('#comment');
reply.value += '>>' + number.innerHTML + '\n';
});
}
const posts = document.querySelectorAll('.post');
for(let post of posts) {
relativeTime(post);
autoQuote(post);
if(!is_moderator) {
removeModTools(post);
}
}
const threads = document.querySelectorAll('.catalog-thread');
for(let thread of threads) {
if(!is_moderator) {
removeModTools(thread);
}
}
>>1456
Who the fuck needs relative time? For what purpose? It's the most useless retarded web 3.0 concept out there. It makes flat design look inspired.
>>2732
Who the fuck needs absolute time? Why do I care that you made your post at 4:50 utc? What I care is if you made your post recently, and are likely to see my reply, or if it was weeks ago and you'll never respond.
>>2740
Absolute time gives you the ability to calculate exact time of posts, response times and timezones. It gives correct dates for screenshots, it can be easily converted to other time formats like unix time, and generally it's entirely better than your plebian format. Disgusting peasant.
[Catalog][Overboard][Update]
[Reply]21 replies
This thread is for sharing custom userscripts for nanochan. These can enable functionality that is usually expected of a non-javascript site.
Always check the source code of your userscripts. Do NOT run untrusted userscripts. If you are worried about your security or anonymity, do not run any userscripts at all.