AO3: Add gifs to comments

Add a gif to a comment on AO3

当前为 2020-10-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 + '"/>';
            });
        }
    });

});