Skip to content

Instantly share code, notes, and snippets.

@stranger777
Last active May 17, 2024 11:24
Show Gist options
  • Save stranger777/d79d58025933708790b1314bc5eab280 to your computer and use it in GitHub Desktop.
Save stranger777/d79d58025933708790b1314bc5eab280 to your computer and use it in GitHub Desktop.
Habr Old Draft Generator. Tampermonkey
// ==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