BetterLM

make Linkomanija great again

目前為 2016-07-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         BetterLM
// @namespace    https://khaos.lt
// @version      1.0
// @description  make Linkomanija great again
// @author       Krupp
// @match        https://www.linkomanija.net/*
// @grant        none
// ==/UserScript==
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var Options = (function () {
    function Options(obj) {
        if (obj) {
            this.NotifyOnUserMention = obj.NotifyOnUserMention;
            this.ShowLastPosts = obj.ShowLastPosts;
        }
    }
    Options.prototype.SetDefaults = function () {
        this.NotifyOnUserMention = true;
        this.ShowLastPosts = true;
    };
    Options.prototype.Validate = function () {
        if (this.NotifyOnUserMention === null || this.ShowLastPosts === null)
            throw 'options not valid';
    };
    return Options;
}());
///<reference path="options.ts"/>
var Settings = (function () {
    function Settings() {
    }
    // singleton
    Settings.Instance = function () {
        if (this._instance)
            return this._instance;
        this._instance = new Settings();
        this._instance._load();
        return this._instance;
    };
    Settings.prototype.Save = function () {
        var optionsJson = JSON.stringify(this.Options);
        localStorage.setItem(Settings.keyOptions, optionsJson);
    };
    Settings.prototype._load = function () {
        try {
            var optionsJson = localStorage.getItem(Settings.keyOptions);
            var options = JSON.parse(optionsJson);
            this.Options = new Options(options);
            this.Options.Validate();
        }
        catch (ex) {
            this.resetOptions();
            this.Save();
        }
        // set own name
        var username = document.querySelector('#username');
        if (username)
            this.OwnName = username.innerText;
    };
    Settings.prototype.resetOptions = function () {
        this.Options = new Options();
        this.Options.SetDefaults();
    };
    Settings.keyOptions = 'blm_options';
    Settings.ApiUrl = 'https://lm.khaos.lt';
    return Settings;
}());
///<reference path="settings.ts"/>
var Base = (function () {
    function Base() {
        this.Settings = Settings.Instance();
    }
    Base.prototype.FetchHTML = function (url, method) {
        if (method === void 0) { method = 'GET'; }
        var request = new XMLHttpRequest();
        request.open(method, Settings.ApiUrl + url, false);
        request.send();
        return request.responseText;
    };
    return Base;
}());
var UserMention = (function () {
    function UserMention(textArea) {
        this._textArea = textArea;
        textArea.oninput = function (evt) {
            var entered = textArea.value[textArea.selectionStart - 1];
            if (entered === '@') {
                var prevSymbol = textArea.value[textArea.selectionStart - 2];
                // check for conditions to display autocomplete
                if (prevSymbol === undefined || prevSymbol === ' ' || prevSymbol === '\n'
                    || prevSymbol === ']' || prevSymbol === ':' || prevSymbol === '>') {
                }
            }
        };
    }
    return UserMention;
}());
///<reference path="../base.ts"/>
///<reference path="../modules/user_mention.ts"/>
var ReplyQuote = (function (_super) {
    __extends(ReplyQuote, _super);
    function ReplyQuote() {
        _super.apply(this, arguments);
    }
    ReplyQuote.prototype.Init = function () {
        var replyTextArea = document.querySelector('textarea');
        var userMention = new UserMention(replyTextArea);
    };
    return ReplyQuote;
}(Base));
///<reference path="../base.ts"/>
///<reference path="../modules/user_mention.ts"/>
var Reply = (function (_super) {
    __extends(Reply, _super);
    function Reply() {
        _super.apply(this, arguments);
    }
    Reply.prototype.Init = function () {
        var replyTextArea = document.querySelector('textarea');
        var userMention = new UserMention(replyTextArea);
    };
    return Reply;
}(Base));
///<reference path="../base.ts"/>
///<reference path="../modules/user_mention.ts"/>
var ViewTopic = (function (_super) {
    __extends(ViewTopic, _super);
    function ViewTopic() {
        _super.apply(this, arguments);
    }
    ViewTopic.prototype.Init = function () {
        var replyTextArea = document.querySelector('textarea');
        var userMention = new UserMention(replyTextArea);
    };
    return ViewTopic;
}(Base));
var Utils = (function () {
    function Utils() {
    }
    Utils.InsertAfter = function (element, newNode) {
        return element.parentElement.insertBefore(newNode, element.nextSibling);
    };
    // seriously fuck JS's .insertBefore with fucking siblings
    Utils.InsertBefore = function (element, newNode) {
        return element.parentElement.insertBefore(newNode, element.previousSibling);
    };
    Utils.GetSelectedValues = function (element) {
        var res = new Array();
        if (element.options) {
            for (var i = 0; i < element.options.length; i++) {
                var opt = element.options[i];
                if (opt.selected)
                    res.push(opt.value);
            }
        }
        return res;
    };
    return Utils;
}());
///<reference path="../base.ts"/>
///<reference path="../utils.ts"/>
var LastPosts = (function (_super) {
    __extends(LastPosts, _super);
    function LastPosts() {
        _super.apply(this, arguments);
    }
    LastPosts.prototype.Init = function () {
        var html = this.FetchHTML('/forums/lastposts/');
        var bottomEl = document.querySelector('p.tcenter:last-child');
        var lastPostsEl = document.createElement('p');
        lastPostsEl.innerHTML = html;
        Utils.InsertAfter(bottomEl, lastPostsEl);
        // set width (fuck css, this hack is awesome)
        var forumTable = document.querySelector('#forum');
        var lastPostTable = document.querySelector('#last-posts');
        lastPostTable.width = forumTable.offsetWidth;
        var contentLinks = lastPostTable.querySelectorAll('td[data-post-id]');
        var _loop_1 = function(i) {
            var postId = contentLinks[i].getAttribute('data-post-id');
            var threadId = contentLinks[i].getAttribute('data-thread-id');
            contentLinks[i].addEventListener('click', function (evt) {
                location.href = "/forums.php?action=viewtopic&topicid=" + threadId + "&page=p" + postId + "#" + postId;
            });
        };
        for (var i = 0; i < contentLinks.length; i++) {
            _loop_1(i);
        }
    };
    return LastPosts;
}(Base));
///<reference path="../base.ts"/>
///<reference path="../modules/last_posts.ts"/>
var Forum = (function (_super) {
    __extends(Forum, _super);
    function Forum() {
        _super.apply(this, arguments);
    }
    Forum.prototype.Init = function () {
        var lastPosts = new LastPosts();
        lastPosts.Init();
    };
    return Forum;
}(Base));
///<reference path="../base.ts"/>
var ForumView = (function (_super) {
    __extends(ForumView, _super);
    function ForumView() {
        _super.apply(this, arguments);
    }
    ForumView.prototype.Init = function () {
        var forumId = Number(location.href.match(/forumid=(\d+)/)[1]);
    };
    return ForumView;
}(Base));
///<reference path="pages/reply_quote.ts"/>
///<reference path="pages/reply.ts"/>
///<reference path="pages/view_topic.ts"/>
///<reference path="pages/forum.ts"/>
///<reference path="pages/forum_view.ts"/>
var BetterLM = (function () {
    function BetterLM() {
    }
    BetterLM.prototype.Init = function () {
        if (this.IsReply)
            new Reply().Init();
        if (this.IsReplyQuote)
            new ReplyQuote().Init();
        if (this.IsViewTopic)
            new ViewTopic().Init();
        if (this.IsForum)
            new Forum().Init();
        if (this.IsForumView)
            new ForumView().Init();
    };
    Object.defineProperty(BetterLM.prototype, "IsReply", {
        get: function () {
            return this._test(/\/forums\.php\?action=reply&topicid=/);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BetterLM.prototype, "IsViewTopic", {
        get: function () {
            return this._test(/\/forums\.php\?action=viewtopic/);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BetterLM.prototype, "IsReplyQuote", {
        get: function () {
            return this._test(/\/forums\.php\?action=quotepost&topicid=/);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BetterLM.prototype, "IsForum", {
        get: function () {
            return this._test(/\/forums\.php$/);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BetterLM.prototype, "IsForumView", {
        get: function () {
            return this._test(/\/forums\.php\?action=viewforum/);
        },
        enumerable: true,
        configurable: true
    });
    BetterLM.prototype._test = function (expr) {
        return expr.test(location.href);
    };
    return BetterLM;
}());
new BetterLM().Init();