Greasy Fork

AO3: Add gifs to comments

Add a gif to a comment on AO3

目前为 2020-10-22 提交的版本。查看 最新版本

// ==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"><button onclick="addGIF">Add this GIF</button></form></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);
    });

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

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

});