Topic: e621 Pool Subscription (Greasemonkey script)

I've developed a small script for myself that I now decided to share here as well. It is a script that let's you follow pools and keeps you updated about them.

First off, the script adds a Follow/Unfollow button for each pool in the pool list page as well in the pool info box of a post that is included in a pool.

Followed pools in the list page have their names yellow for better recognition. When a pool got updated (specifically: its number of posts has been changed) since last checking the pool, its name in the list page will be bolded.

Under the search bar of the pool page is a button that lets you toggle a table with all pools you are following, although this won't be able to show if a pool got updated yet.

Please bear in mind that this script isn't written on a high professional level as of now, and it may break in combination with other scripts. Also remember that re-installing the script will reset all your followed pools.

I don't feel comfortable posting the script at any extern repository right now, so instead I will post the code right here in the section below. If you have Greasemonkey installed in your browser, click on 'New User script...', select the script (which will be called something like 'Unnamed script...'), click 'Edit' and paste the code in the newly opened browser page, then hit save. Done!

Script

// ==UserScript==
// @name e621 Pool Subscription
// @author Ecstatis
// @namespace *
// @include *://e621.net/pool
// @include *://e621.net/pool/index
// @include *://e621.net/pool?*
// @include *://e621.net/post/show/*
// @version 1
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @grant GM.setValue
// @grant GM.getValue
// ==/UserScript==

const HIGHLIGHT_NEW_POOLS = false;

var style = document.createElement('style');
document.head.appendChild(style);
style.sheet.insertRule('a.follow-button {text-decoration: underline; cursor: pointer;}');

(async () => {
var pools = await GM.getValue('pools', {});

if (/.*e621\\.net\\/post\\/show\\/.*/.test(window.location.href)) {
$('div.status-notice:not(#child-posts) > div').each(function () {
var pool_index = $(this).attr('id').substr(4);
var name = $(this).children('p').first().find('a').html();

var follow_button = $('<a>')
.addClass('follow-button')
.html("Follow")
.click(async function() {
if (pools[pool_index] == null) {
pools[pool_index] = {name: name, entries: '?'};
$(this).html("Unfollow");
} else if (confirm('Unfollow pool?')) {
pools[pool_index] = null;
$(this).html("Follow");
}
GM.setValue('pools', pools);
});
$(this).find('p').last().css('text-align', 'center').append(follow_button);

if (pools[pool_index] != null)
$(follow_button).html("Unfollow");
});
} else {
style.sheet.insertRule('tr.pool-follow a.pool-name {color: #FFDEAD;}');
style.sheet.insertRule('tr.pool-new a.pool-name {color: #00FF00;}');
style.sheet.insertRule('tr.pool-checkworthy a.pool-name {text-decoration: underline;}');
style.sheet.insertRule('tr.pool-update a.pool-name {font-weight: bold;}');

$("#pool-index thead tr")
.append($('<th>').attr('width', '5%'))
.children().first().attr('width', '65%');

var follow_table_built = false;
var show_followed_pools = false;
$("#pool-index div.section")
.append($('<button>')
.html('Show followed pools')
.click(function () {
if (show_followed_pools) {
$('#follow-table').css('display', 'none');
$('#follow-table tbody').empty();
$(this).html('Show followed pools');
} else {
if (follow_table_built)
$('#follow-table').css('display', 'table');
else {
var follow_table = $('<table>')
.addClass('rounded')
.attr('id', 'follow-table')
.attr('width', '100%')
.append($('<thead>')
.append($('<tr>')
.append($('<th>')
.attr('width', '80%')
.html('Name'))
.append($('<th>')
.attr('width', '15%')
.html('Posts'))
.append($('<th>')
.attr('width', '5%')
.html(''))
))
.append($('<tbody>'));
$("#pool-index div.section").after(follow_table);
follow_table_built = true;
}

$.each(pools, function (pool_index, pool) {
if (pool == null)
return true;
var pool_row = $('<tr>')
.addClass('pool-follow')
.append($('<td>')
.append($('<a>')
.addClass('pool-name')
.attr('href', '/pool/show/' + pool_index)
.html(pool.name)))
.append($('<td>')
.html(pool.entries))
.append($('<td>')
.append($('<a>')
.addClass('follow-button')
.html("Unfollow")
.click(function () {
if (pools[pool_index] == null) {
pools[pool_index] = pool;
$(pool_row).addClass('pool-follow');
$(this).html("Unfollow");
} else if (confirm('Unfollow pool?')) {
pools[pool_index] = null;
$(pool_row).removeClass('pool-follow');
$(this).html("Follow");
}
GM.setValue('pools', pools);
})));
$('#follow-table tbody').append(pool_row);
});
$(this).html('Hide followed pools');
}
show_followed_pools = !show_followed_pools;
}));

$("#pool-index tbody tr").each(function () {
var pool_row = $(this);
var link = $(pool_row).find('a').first().addClass('pool-name');
var name = $(link).html();
var pool_index = $(link).attr('href').split("/").pop();
var pool_entries = Number.parseInt($(pool_row).find('td:eq(2)').html());

var follow_button = $('<a>')
.addClass('follow-button')
.html("Follow")
.click(function () {
if (pools[pool_index] == null) {
pools[pool_index] = {name: name, entries: pool_entries};
$(pool_row).addClass('pool-follow');
$(this).html("Unfollow");
} else if (confirm('Unfollow pool?')) {
pools[pool_index] = null;
$(pool_row).removeClass('pool-follow');
$(this).html("Follow");
}
GM.setValue('pools', pools);
});

if (!pools.hasOwnProperty(pool_index)) {
if (HIGHLIGHT_NEW_POOLS)
$(pool_row).addClass('pool-new');
pools[pool_index] = null;
} else if (pools[pool_index] != null) {
$(pool_row).addClass('pool-follow');
$(follow_button).html("Unfollow");
if (pool_entries != pools[pool_index].entries) {
$(pool_row).addClass('pool-update');
pools[pool_index].entries = pool_entries;
}
}
$(pool_row).append($("<td>").append(follow_button));
});

GM.setValue('pools', pools);
}
})();

If you have any questions or want to report any bugs, feel free to comment or PM me directly. I'm online quite irregularly but I'll try and look into any request eventually.

EDIT: Pasting the code into here killed some escape symbols, just fixed that.

Updated by savageorange