Skip to content

Instantly share code, notes, and snippets.

@Kenya-West
Created June 26, 2020 12:36
Show Gist options
  • Save Kenya-West/b882818069dbafccee992a86934456ed to your computer and use it in GitHub Desktop.
Save Kenya-West/b882818069dbafccee992a86934456ed to your computer and use it in GitHub Desktop.
Raw-text-copier-for-TV-Programmes

Description

A js file for Tampermonkey that adds raw text for easier copying into any app as a plain text for Yandex TV and Mail.ru TV programmes . This project is a script for Yandex and Mail.ru TV websites.

How to contribute

Clone this project on GitHub and start your changes. If you want to use the script from source code, then create new script in Tampermonkey extension and put source code in opened window.

How to use this script?

You need Tampermonkey extension installed on your browser to use this style.

You can install the script from Greasyfork.

P. S. Author is not affiliated in any kind of mentioned organizations.

// ==UserScript==
// @name Raw text copier for TV programmes
// @namespace http://tampermonkey.net/
// @version 0.1
// @description This is a script for Yandex TV and Mail.ru TV programmes that adds raw text for easier copying into any app as a plain text
// @author Kenya-West
// @match https://tv.mail.ru*
// @match https://tv.yandex.ru*
// @grant none
// ==/UserScript==
setInterval(function () {
main()
}, 500)
function main() {
let textarea;
document.querySelector("#textarea__rawtext") ? textarea = document.querySelector("#textarea__rawtext") : textarea = createTextarea();
textarea ? textarea.value = getInfo() : null;
function createTextarea() {
const textarea = document.createElement("textarea");
textarea.id = "textarea__rawtext";
textarea.classList = ["cols__column cols__column_small_14"];
textarea.style.height = 300;
const parent = document.querySelector(".cols__column_sidebar > .cols__inner");
const ad = document.querySelector(".cols__column_sidebar > .cols__inner > .sticky-springs");
if (ad && parent) document.querySelector(".cols__column_sidebar > .cols__inner").insertBefore(textarea, ad);
return textarea;
}
function getInfo() {
let rawText = "";
document.querySelectorAll(".p-channels__items > .p-channels__item").forEach((element) => {
rawText = rawText + element.querySelector(".p-channels__item__info .p-channels__item__info__title__link").innerText.replace(/LIVE$/gi, "") + "\n\n";
element.querySelectorAll(".p-programms__items > .p-programms__item").forEach((item) => {
let info = "";
info = item.querySelector(".p-programms__item__time__value").innerText;
info = info + " " + item.querySelector(".p-programms__item__name__link").innerText;
rawText = rawText + info + "\n";
});
rawText = rawText + "\n\n";
});
return rawText;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment