Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name MyAnimeList(MAL) - Preview BBCODE with Character Count
- // @version 1.0.4
- // @description This script adds the MAL BBCODE Editor and character count.
- // @author Cpt_mathix
- // @match https://myanimelist.net/*
- // @grant none
- // @run-at document-body
- // @namespace https://greasyfork.org/users/16080
- // ==/UserScript==
- init();
- function init() {
- var fancyboxInitObserver = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- var fancybox = document.getElementById("fancybox-wrap");
- var fancyboxInner = document.getElementById("fancybox-inner");
- if (fancybox) {
- fancyboxInitObserver.disconnect();
- var fancyboxObserver = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (fancybox.style.width !== "1000px") {
- fancybox.style.width = "1000px";
- fancyboxInner.style.width = "980px";
- }
- window.dispatchEvent(new Event('resize'));
- });
- });
- fancyboxObserver.observe(fancybox, { attributes: true });
- }
- });
- });
- fancyboxInitObserver.observe(document.body, { childList: true });
- if (document.location.href.includes("myanimelist.net/clubs")) {
- initClubCommentsPreview();
- }
- if (document.location.href.includes("myanimelist.net/blog.php")) {
- initBlogCommentsPreview();
- }
- if (document.location.href.includes("myanimelist.net/myblog.php")) {
- initBlogEntryPreview();
- }
- if (document.location.href.includes("myanimelist.net/editprofile.php")) {
- initProfileAboutMePreview();
- }
- if (document.location.href.includes("myanimelist.net/ownlist/manga")) {
- initEditMangaPreview();
- }
- if (document.location.href.includes("myanimelist.net/ownlist/anime")) {
- initEditAnimePreview();
- }
- observeBBCodeTextareas();
- }
- function initClubCommentsPreview() {
- addEditor("form.form-club-user-comment textarea");
- }
- function initBlogCommentsPreview() {
- addEditor(".blog_detail_comment_wrapper form textarea");
- }
- function initEditMangaPreview() {
- resizeDialog();
- addEditor("#add_manga_comments");
- }
- function initEditAnimePreview() {
- resizeDialog();
- addEditor("#add_anime_comments");
- }
- function initBlogEntryPreview() {
- resizeDialog();
- addEditor("#blogForm textarea[name=\"entry_text\"]");
- }
- function initProfileAboutMePreview() {
- var textarea = document.querySelector("#content form textarea[name=\"profile_aboutme\"]");
- if (textarea) {
- textarea.classList.add("bbcode-message-editor");
- textarea.insertAdjacentHTML("afterend", "<small><b>You can also preview bbcode with: <a href='https://cptmathix.github.io/MyAnimeList-BBCODE2HTML/'>https://cptmathix.github.io/MyAnimeList-BBCODE2HTML/</a><b></small>");
- }
- }
- function resizeDialog() {
- var dialog = document.getElementById("dialog");
- if (dialog) {
- if (document.location.href.includes("hideLayout=1")){
- var clientWidth = document.body.clientWidth;
- dialog.style.width = clientWidth + "px";
- } else {
- dialog.style.width = "804px";
- }
- }
- }
- function addEditor(selector) {
- var textarea = document.querySelector(selector);
- if (textarea) {
- textarea.classList.add("bbcode-message-editor");
- textarea.rows = 15;
- }
- }
- function addCharacterCount(textarea) {
- var counter = document.createElement("div");
- counter.style.fontSize = "small";
- counter.style.color = "#888";
- counter.textContent = "Characters: " + textarea.value.length;
- counter.classList.add("character-count-display");
- textarea.parentNode.insertBefore(counter, textarea.nextSibling);
- textarea.addEventListener("input", function() {
- counter.textContent = "Characters: " + textarea.value.length;
- });
- }
- function observeBBCodeTextareas() {
- var sceditorInitObserver = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- mutation.addedNodes.forEach(function(node) {
- if (node.nodeType === Node.ELEMENT_NODE) {
- var textareas = node.querySelectorAll(".sceditor-container textarea");
- textareas.forEach(function(textarea) {
- if (!textarea.nextElementSibling || !textarea.nextElementSibling.classList.contains('character-count-display')) {
- addCharacterCount(textarea);
- }
- });
- }
- });
- });
- });
- sceditorInitObserver.observe(document.body, { childList: true, subtree: true });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement