Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
qt-kaneko committed Oct 18, 2022
1 parent cb89abd commit c4b04f4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
12 changes: 12 additions & 0 deletions design.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file is part of YouTube Only Music.
//
// YouTube Only Music is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// YouTube Only Music is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with YouTube Only Music. If not, see <https://www.gnu.org/licenses/>.
// Copyright 2022 Kaneko Qt

document.styleSheets[0].insertRule(`#main-panel { display: none !important; }`);
document.styleSheets[0].insertRule(`.side-panel.ytmusic-player-page { max-width: unset !important; width: 100% !important; margin: unset !important; }`);
document.styleSheets[0].insertRule(`.content.style-scope.ytmusic-player-page { padding: unset !important; }`);
37 changes: 37 additions & 0 deletions logic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This file is part of YouTube Only Music.
//
// YouTube Only Music is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// YouTube Only Music is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with YouTube Only Music. If not, see <https://www.gnu.org/licenses/>.
// Copyright 2022 Kaneko Qt

var inject = function () {
const proxied = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url) {
if (url.indexOf("mime=audio") !== -1) {
var video = document.querySelector("video");
video.onloadeddata = function () {
var sections = url.split('?');
if (sections.length > 1) {
var keys = ['rn', 'rbuf', 'range'];
var parameters = sections[1].split(/[&;]/g);
keys.forEach(k => { parameters = parameters.filter((p) => !p.startsWith(encodeURIComponent(k) + '=')) });
url = sections[0] + '?' + parameters.join('&');
if (video.src !== url) {
video.pause();
video.src = url;
video.currentTime = 0;
video.play();
}
}
};
}
return proxied.apply(this, arguments);
};
};
/* */
var script = document.createElement("script");
script.textContent = "(" + inject + ")()";
document.documentElement.appendChild(script);
20 changes: 20 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"manifest_version": 2,
"name": "YouTube Only Music",
"version": "1.0.0",

"description": "Load only audio on YouTube Music.",

"content_scripts": [
{
"matches": ["*://music.youtube.com/*"],
"js": ["./logic.js"],
"run_at": "document_start"
},
{
"matches": ["*://music.youtube.com/*"],
"js": ["./design.js"],
"run_at": "document_end"
}
]
}

0 comments on commit c4b04f4

Please sign in to comment.