// ==UserScript== // @name AO3: Floating Comment Box - Redux // @namespace https://greasyfork.org/en/users/906106-escctrl // @version 0.11 // @description my version of the floating comment box script by ScriptMouse // @author escctrl // @license MIT // @match *://archiveofourown.org/works/* // @exclude *://archiveofourown.org/works/*/new // @exclude *://archiveofourown.org/works/*/edit* // @exclude *://archiveofourown.org/works/new* // @require https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js // @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js // @grant none // @downloadURL none // ==/UserScript== (function($) { 'use strict'; // done: get a floating comment box that is not modal (you can move it around) and resizable // done: make it work on mobile XD // done: make it submit the comment directly, no need to copy it elsewhere (like owl's comment from bins) // done: cache comment text // done: insert highlighted text directly in comment (in italics or blockquote) // done: character counter // done: open it from a nicely placed button // done: while submitting, show some sort of progress & load the page to the new comment if possible // done: make it open at the position where it was last closed // done: choice of pseud // KNOWN ISSUE: when closing the dialog, the screen scrolls back up to top >:( // GOAL: make it work with my Comment Formatting script (that means adapting the other script) // button at top of work to open the modal let cmtButton = `
  • Floating Comment
  • `; $('#show_comments_link_top').after(cmtButton); var dlg = "#float_cmt_dlg"; let dialogtheme = lightOrDark($('body').css('background-color')) == "dark" ? "ui-darkness" : "base"; // if the background is dark, use the dark UI theme to match let fontsize = $("#main #chapters .userstuff").css('font-size'); // enforce the reading font size for the dialog $("head").append(``) .append(``); // prepping the dialog (without opening it) createCommentBox(); // open or reopen the dialog when the button is clicked $('#float_cmt_button').on('click', (e) => { e.preventDefault(); openCommentBox(); }); // prepares the dialog and loads the cache into it function createCommentBox() { // designing the floating box $("body").append(`
    `); // optimizing the GUI in case it's a mobile device let screen = parseInt($("body").css("width")); // parseInt ignores letters (px) let buttonText = screen <= 500 ? false : true; let dialogwidth = screen <= 500 ? screen * 0.9 : 500; let resize = screen <= 500 ? false : true; $(dlg).dialog({ modal: false, autoOpen: false, resizable: resize, draggable: true, width: dialogwidth, position: { my: "right bottom", at: "right bottom" }, title: "Comment", buttons: [ { text: "Quote", icon: "ui-icon-caret-2-e-w", showLabel: buttonText, click: () => { grabHighlight(); } }, { text: "Discard", icon: "ui-icon-trash", showLabel: buttonText, click: () => { discardComment(); } }, { text: "Post", icon: "ui-icon-comment", showLabel: buttonText, click: () => { submitComment(); } }, { text: "Close", icon: "ui-icon-close", showLabel: buttonText, click: () => { closeCommentBox(); } }, ], // positioning stuff below is so that it SCROLLS WITH THE PAGE JFC https://stackoverflow.com/a/9242751/22187458 create: function(event, ui) { $(event.target).parent().css('position', 'fixed'); // and also to put the dialog where it was last left across pageloads let cachemap = new Map(JSON.parse(localStorage.getItem('floatcmt'))); if (cachemap.get('pos')) { let pos = JSON.parse(cachemap.get('pos')); pos.of = $(window); $(dlg).dialog('option','position', pos); } // issue: if you drag it around so far that the screen begins to scroll, the dialog disappears. need to refresh the page to get it back // workaround: force the dialog to stay within the visible screen - no dragging outside of viewport means it can't disappear $(dlg).dialog("widget").draggable("option","containment","window"); }, resizeStop: function(event, ui) { let position = [(Math.floor(ui.position.left) - $(window).scrollLeft()), (Math.floor(ui.position.top) - $(window).scrollTop())]; $(event.target).parent().css('position', 'fixed'); $(dlg).dialog('option','position',position); } }); $(dlg).html(`
    Comment as
    10000 characters left
    `); // add the pseud selection to the dialog so we know which one to submit with let pseud_id = $("#add_comment_placeholder [name='comment[pseud_id]']").get(0); // available pseuds - either a hidden , or a or