'Changing default value of DOM JavaScript for Y2mate.com
Here's a script got from Y2mate.com I tweaked a bit, instead of downloading video it downloads Mp3.
When I click on the "Download" button. It opens this page , on this page you can see the default option is 128kbps.
Is it possible to change it? How can I change it to 320kbps as default?
Just re-Formatted same code for readability--
// ==UserScript==
// @name Y2mate Converter Button
// @namespace https://y2mate.com/
// @version 1.5
// @date 2019-07-23
// @author A Koi
// @description Y2mate Downloader: Download Video and Audio for free
// @homepage https://y2mate.com/
// @icon https://y2mate.com/themes/images/logo.png
// @icon64 https://y2mate.com/themes/images/logo.png
// @updateURL https://app.y2mate.com/extensions/chrome/helper.meta.js
// @downloadURL https://app.y2mate.com/extensions/chrome/helper.user.js
// @include http://*
// @include https://*
// @run-at document-end
// @grant GM_listValues
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// @grant GM_info
// @grant GM_openInTab
// @grant GM_setClipboard
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_notification
// @grant GM_download
// @grant GM.info
// @grant GM.listValues
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.deleteValue
// @grant GM.openInTab
// @grant GM.setClipboard
// @grant GM.xmlHttpRequest
// @connect youtube.com
// @connect m.youtube.com
// @connect www.youtube.com
// @connect youtube-nocookie.com
// @connect youtu.be
// @connect y2mate.com
// @connect self
// @connect *
// ==/UserScript==
var AKoiMain = {
oXHttpReq: null,
vid: null,
oldUrl: null,
DocOnLoad: function(o) {
try {
if (null != o && null != o.body && null != o.location && (AKoiMain.vid = AKoiMain.getVid(o), AKoiMain.vid)) {
o.querySelector("#info-contents #info").setAttribute("style", "flex-wrap: wrap;");
var t = o.querySelector("#menu-container"),
e = o.querySelector("#y2mateconverter"),
n = AKoiMain.GetCommandButton();
null == e && (null != t ? t.parentNode.insertBefore(n, t) : (t = o.querySelector("#eow-title")).parentNode.insertBefore(n, t)), AKoiMain.oldUrl = o.location.href, AKoiMain.checkChangeVid()
}
return !0
} catch (o) {
console.log("Ошибка в функции Y2mate.DocOnLoad. ", o)
}
},
checkChangeVid: function() {
setTimeout(function() {
AKoiMain.oldUrl == window.location.href ? AKoiMain.checkChangeVid() : AKoiMain.WaitLoadDom(window.document)
}, 1e3)
},
WaitLoadDom: function(o) {
AKoiMain.vid = AKoiMain.getVid(o), AKoiMain.vid ? null != o.querySelector("#info #menu-container") ? AKoiMain.DocOnLoad(o) : setTimeout(function() {
AKoiMain.WaitLoadDom(o)
}, 1e3) : AKoiMain.checkChangeVid()
},
goToY2mate: function(o) {
try {
var t = "https://y2mate.com/youtube-mp3/" + AKoiMain.vid + "/?utm_source=chrome_addon";
window.open(t, "_blank")
} catch (o) {
console.log("", o)
}
},
GetCommandButton: function() {
try {
var o = document.createElement("button");
return o.id = "y2mateconverter", o.className = "yt-uix-tooltip", o.setAttribute("type", "button"), o.setAttribute("title", "Download MP3 320kbps"), o.innerHTML = "MP3", o.addEventListener("click", function(o) {
AKoiMain.goToY2mate(o)
}, !0), o.setAttribute("style", "min-height:25px; position:relative; top:1px; cursor: pointer; font: 13px Arial; background: #4F6C38; color: #fff; text-transform: uppercase; display: block; padding: 10px 16px; margin: 10px 5px 10px 5px; border: 1px solid #4F6C38; border-radius: 2px; font-weight:bold"), o.setAttribute("onmouseover", "this.style.backgroundColor='#4F6C38'"), o.setAttribute("onmouseout", "this.style.backgroundColor='#4F6C38'"), o
} catch (o) {
console.log("", o)
}
},
getVid: function(o) {
var t = o.location.toString().match(/^.*((m\.)?youtu\.be\/|vi?\/|u\/\w\/|embed\/|\?vi?=|\&vi?=)([^#\&\?]*).*/);
return !(!t || !t[3]) && t[3]
}
};
AKoiMain.WaitLoadDom(window.document);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|