Created
August 12, 2024 03:39
-
-
Save dclamage/295aa2ef7c23b2de4397109b34d19600 to your computer and use it in GitHub Desktop.
Makes the caption input taller when uploading TikTok videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Make Caption Editor Resizable | |
// @namespace http://tampermonkey.net/ | |
// @version 1.5 | |
// @description Make the caption editor resizable (updated for main document) | |
// @author Your Name | |
// @match https://www.tiktok.com/creator-center* | |
// @match https://www.tiktok.com/tiktokstudio* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to apply the required styles to the caption editor | |
function applyStylesToCaptionEditor() { | |
if (!document.querySelector('#caption-editor-resize-style')) { | |
console.log('*************************** Applying styles to caption editor'); | |
const style = document.createElement('style'); | |
style.id = 'caption-editor-resize-style'; | |
style.innerHTML = ` | |
.caption-editor { | |
height: 15rem !important; | |
max-height: none !important; | |
resize: vertical !important; | |
overflow-y: auto !important; | |
} | |
`; | |
document.head.appendChild(style); | |
} | |
} | |
// Function to wait for the caption editor to load and then apply styles | |
function waitForCaptionEditorAndApplyStyles() { | |
const captionEditor = document.querySelector('.caption-editor'); | |
if (captionEditor) { | |
applyStylesToCaptionEditor(); | |
console.log('*************************** Styles applied to caption editor'); | |
} else { | |
console.log('*************************** Caption editor not found, retrying...'); | |
setTimeout(waitForCaptionEditorAndApplyStyles, 1000); // Retry after 1 second | |
} | |
} | |
// Observe the document for changes and reapply styles if necessary | |
const observer = new MutationObserver((mutations) => { | |
for (const mutation of mutations) { | |
if (mutation.type === 'childList') { | |
waitForCaptionEditorAndApplyStyles(); | |
} | |
} | |
}); | |
observer.observe(document.body, { childList: true, subtree: true }); | |
console.log('*************************** Added observer'); | |
// Initial call to apply styles | |
waitForCaptionEditorAndApplyStyles(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment