[MyAnimeList] Advanced BBCode Editor

Advanced BBCode Editor for MyAnimeList.net

目前為 2018-07-24 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         [MyAnimeList] Advanced BBCode Editor
// @namespace    https://github.com/Skqnder
// @version      0.2
// @description  Advanced BBCode Editor for MyAnimeList.net
// @author       Skqnder
// @license 	 MIT

// @include      *://myanimelist.net/forum*
// @include      *://myanimelist.net/mymessages*
// @include      *://myanimelist.net/editprofile*
// @include      *://myanimelist.net/myblog*
// @include      *://myanimelist.net/clubs*
// @include      *://myanimelist.net/profile*
// @include      *://myanimelist.net/editprofile
// @include      *://myanimelist.net/comtocom*
// @include      *://myanimelist.net/comments*
// @include      *://myanimelist.net/editlist*
// @include      *://myanimelist.net/panel*
// @include      *://myanimelist.net/people*
// @include      *://myanimelist.net/myfriends*
// @include      *://myanimelist.net/blog*
// @exclude      *://myanimelist.net/editprofile.php?go=stylepref&do=cssadv&id=*

// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/sceditor.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/icons/monocons.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/formats/bbcode.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/plugins/autosave.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/plugins/autoyoutube.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/plugins/plaintext.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/plugins/undo.js

// @icon         https://www.google.com/s2/favicons?domain=myanimelist.net
// @compatible   firefox Tested with Tampermonkey
// @compatible   chrome Tested with Tampermonkey
// @compatible   opera Tested with Tampermonkey Beta
// @grant        none
// ==/UserScript==

'use strict';

(function() {

    $("head").append ('<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/themes/square.min.css" >');

    sceditor.command.set('date', {
        exec: function () {
            function _date(editor) {
                var	now = new Date(),
                    year = now.getYear(),
                    month = now.getMonth() + 1,
                    day = now.getDate();

                if (year < 2000) {
                    year = 1900 + year;
                }

                if (month < 10) {
                    month = '0' + month;
                }

                if (day < 10) {
                    day = '0' + day;
                }

                var mm = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
                month = mm[month - 1];

                return editor.opts.dateFormat
                    .replace(/year/i, year)
                    .replace(/month/i, month)
                    .replace(/day/i, day);
            }
            this.insertText(_date(this));
        },
        txtExec: function () {
            this.insertText(_date(this));
        },
        tooltip: 'Insert current date'
    },);

    sceditor.command.set('time', {
        exec: function () {
            function _time() {
                var	now = new Date(),
                    hours = now.getHours(),
                    mins = now.getMinutes(),
                    suf = ' AM';

                if (hours > 12) {
                    hours = hours-12;
                    suf = ' PM';
                }

                if (hours < 10) {
                    hours = '0' + hours;
                }

                if (mins < 10) {
                    mins = '0' + mins;
                }

                return hours + ':' + mins + suf;
            }
            this.insertText(_time());
        },
        txtExec: function () {
            this.insertText(_time());
        },
        tooltip: 'Insert current time'
    },);

    for (var i = 0; i < $('.textarea').length; i++) {
        var textarea = $('.textarea')[i];
        sceditor.create(textarea, {
            format: 'bbcode',
            icons: 'monocons',
            dateFormat: 'month day, year',
            style: '//cdnjs.cloudflare.com/ajax/libs/sceditor/2.1.3/themes/content/default.min.css',
            plugins: 'autosave,autoyoutube,plaintext,undo',
            toolbar: 'source|bold,italic,underline,strike|center,right|color,removeformat|code,quote,image,youtube|link,unlink|date,time|print,maximize',
            //toolbar: 'source|bold,italic,underline,strike|left,center,right|size,color,removeformat|bulletlist,orderedlist|code,quote,image,youtube|link,unlink|date,time|print,maximize',
            emoticonsEnabled: false,
            autoExpand: true,
            enablePasteFiltering: true,
            autosave: {
                storageKey: 'sce-autodraft-' + i.toString() + location.pathname + location.search,
                expires: 180000
            },
        });
    }

})();