AO3: Add gifs to comments

Add a gif to a comment on AO3

目前為 2020-10-22 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        AO3: Add gifs to comments
// @description Add a gif to a comment on AO3
// @namespace
// @author	starrybouquet
// @version	0.0.1
// @grant       none
// @require     https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// @include     http://*archiveofourown.org/*
// @include     https://*archiveofourown.org/*
// @namespace https://greasyfork.org/users/695969
// ==/UserScript==


$(document).ready(function () {

    var DEBUG = false;

    // newest more-or-less major version, for the update notice
    var current_version = '0.0.1';

    // regex for url checking
    var expression =
/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
    var regex = new RegExp(expression);

    // create entry form
    var gif_div = $('<div id="gifentry"><form><label for="gifaddress">GIF link:</label><input type="text" name="gifaddress" id="gifaddress"></form><button id="addGIF">Add this GIF</button></div>');
    var main = $('#main');
    var work_ids = [];

    // if it's the first time after an update
    // addNotice();

    // if it's a work page
    if ($('#workskin').length) {

        // get work id
        var work_id = $('#kudo_commentable_id').val();
        // DEBUG && console.log('work_id ' + work_id);

        work_ids.push(work_id);
    }

    // add a gif entry to every comment form
    $(".post.comment").each(function ( index ) {
        $(this).find("h4").append(gif_div);
    });

    $("#addGIF").click(function (e) {
        e.preventDefault();
        var url = $(this).sibilings('#gifaddress').val();

        if (url.match(regex)){
            $(".post.comment").find('textarea.comment_form').val(function() {
                return this.value + '<img src="' + url + '"/>';
            });
        }
    });

});