/meta/ - Board Meta

[Make a Post]
[X]





Userscripts Thread hakase ## Nanochan Administrator No.381 (S)[D][U][F][S][L][A][C]
File: 6946a4d4a0047d8614857fb32b5b7683749ff3ac4f8ba21a7b4c8ecaddd51d02.png (dl) (782.25 KiB)

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.

Nanonymous No.391 [D] >>404

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");
}
})();



Nanonymous No.392 [D] >>394

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]);
}
})();

Nanonymous No.393 [D]

May be a good idea to implement [code] blocks too or allow for uploading user.js files directly.

Nanonymous No.394 [D] >>395

>>392
Mod links don't show up for me anymore. I think this script is obsolete.

Nanonymous No.395 [D] >>396

>>394
I think you're right. Funny how quick it happened!

Nanonymous No.396 [D][U][F]
File: dded66842d458b49aeaacc1de7f6785f57e308c4b444d7edf63566b08f0350d2.png (dl) (25.42 KiB)

>>395
hakase beat you by 10 minutes lol

Nanonymous No.404 [D] >>589

>>391
How does one use these script things? I got to copy paste them somewhere right?


Nanonymous No.589 [D]

>>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)"

Nanonymous No.1299 [D] >>1308

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);
}
}
})();

Nanonymous No.1308 [D] >>1327

>>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)

Nanonymous No.1327 [D]

>>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

Nanonymous No.1329 [D] >>1331 >>1332 >>1335

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

Nanonymous No.1331 [D] >>1333

>>1329
>having ever used twitter in the first place
Fuck off nigger relative post times are useful.

Nanonymous No.1332 [D] >>1333

>>1329
Hover over the post time faggot

Nanonymous No.1333 [D]

>>1331
Useful for web 2.0 faggots? It gives off a "gay discord goon tranny" feel, it always has.

>>1332
Thanks, but it still looks gay as fuck, Anon. It also ruins screenshots and makes them impossible to date.

hakase No.1335 [D]

>>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).

Nanonymous No.1344 [D]

>>1337
Thank fuck.

Nanonymous No.1456 [D] >>2732

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);
}
}

Nanonymous No.2732 [D] >>2740

>>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.

Nanonymous No.2740 [D] >>2741

>>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.

Nanonymous No.2741 [D]

>>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.