Last active
May 17, 2024 11:24
-
-
Save stranger777/d79d58025933708790b1314bc5eab280 to your computer and use it in GitHub Desktop.
Habr Old Draft Generator. Tampermonkey
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 Habr Old Draft Generator | |
// @version 0.1 | |
// @description Autofills a text field with the provided text if it's empty. Generate a draft for the Habr. | |
// @author Novikov Ivan | |
// @match https://habr.com/ru/topic/add/* | |
// @match https://habr.com/ru/article/edit/*/ | |
// @namespace https://habr.com/ | |
// @grant none | |
// @run-at | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
const getFormattedDate = () => | |
new Date().toLocaleString("ru-RU", { | |
day: "numeric", | |
month: "numeric", | |
year: "numeric", | |
hour: "numeric", | |
minute: "numeric" | |
}); | |
function fillTextFieldIfEmpty(selector, text) { | |
var element = document.querySelector(selector); | |
if (element.value === "") { // чтобы скрипт не лез, куда не надо | |
element.value = text; | |
} | |
} | |
fillTextFieldIfEmpty( | |
"div.item.title.required > input[type=text]", // Заголовок | |
"Черновик " + getFormattedDate() // Момент генерации до минуты — можно вспомнить, что и когда было | |
); | |
fillTextFieldIfEmpty( | |
"#text_textarea", | |
`<a href="https://habr.com/ru/articles//"><img src="" height="780" width="440"></a>\n\n` + // КДПВ со ссылкой на пост | |
"Для ката. ".repeat(10) + // Требование 100 символов до ката. | |
"\n" + | |
'<cut text="Читать далее" />\n' + // Чтобы не вспоминать текст кнопки по умолчанию. | |
"<hr />" + // Горизонтальная черта (большое спасибо @klimensky). | |
"\n" // Для удобства ввода после клика по полю. | |
); | |
fillTextFieldIfEmpty( | |
"div.item.tags_string.required > input[type=text]", // метка | |
"novikoiva" // :) | |
); | |
fillTextFieldIfEmpty( | |
"div.item.link.required > input[type=text]", | |
"https://trans.late" | |
); | |
fillTextFieldIfEmpty( | |
"div.item.translation_author.required > input[type=text]", | |
"Original Autor" // autor не синоним author | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment