Snuggledash icon

/qa/ on the frontpage!

Snuggledash | PRO | 11/03/18 10:17:03 PM UTC | 0 ⭐ | 705 👁️ | Never ⏰ | []
JavaScript |

2.05 KB

|

None

|

0 👍

/

0 👎

// ==UserScript==
// @name         /qa/ on the frontpage!
// @namespace    http://www.4chan.org/
// @version      1022
// @description  Adds /qa/ to the frontpage of 4chan
// @author       (You)
// @match        http://4chan.org/
// @match        https://4chan.org/
// @match        http://www.4chan.org/
// @match        https://www.4chan.org/
// @match        http://4channel.org/
// @match        https://4channel.org/
// @match        http://www.4channel.org/
// @match        https://www.4channel.org/
// @grant        none
// ==/UserScript==
 
(function() {
    'use strict';
    try {
        let full_taste = location.hostname.endsWith('4chan.org');
        var board_list;
        if (full_taste) {
            //board_list = document.querySelector('a.boardlink[href$="/pol/"]').parentNode.parentNode;
            // in case some madman actually ever deletes /pol/
            board_list = document.querySelector('a.boardlink[href$="/b/"]').parentNode.parentNode;
        } else {
            // There's no Misc category on 4channel! What do we do?
            // Well, /qa/ is certainly an important board.
            board_list = document.querySelector('a.boardlink[href$="/vip/"]').parentNode.parentNode;
        }
        let qa_link = document.createElement('a');
        // XXX: adapt in case worksafe boards become exclusive to 4channel
        qa_link.setAttribute('href', '//boards.' + (full_taste ? '4chan' : '4channel') + '.org/qa/');
        qa_link.classList.add('boardlink');
        qa_link.appendChild(document.createTextNode('Question & Answer'));
        let qa_entry = document.createElement('li');
        qa_entry.appendChild(qa_link);
        board_list.appendChild(qa_entry);
    // } catch (NullPointerException ex) {
    // Oh, wait. There's no Java in Javascript.
    } catch (err) {
        if (err instanceof TypeError) {
            console.error('Could not found the Misc/Other category on the frontpage! This is kind of bad news.');
            return;
        } else {
            throw(err);
        }
    }
})();

Comments