Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* global $, jQuery */
- // ==UserScript==
- // @name JPopSuki Folder Name Formatter
- // @author Nitori
- // @description Automatically formats and copies to clipboard the appropriate folder name
- // @include *jpopsuki.eu/torrents.php?id=*
- // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
- // @version 1.0
- // ==/UserScript==
- //-----------------------------------------------------------
- this.$ = this.jQuery = jQuery.noConflict(true); // Avoid duplicate jQuery conflict
- //-----------------------------------------------------------
- function copyToClipboard (str) {
- var el = document.createElement('textarea');
- el.value = str;
- el.setAttribute('readonly', '');
- el.style = {position: 'absolute', left: '-9999px'};
- document.body.appendChild(el);
- el.select();
- document.execCommand('copy');
- document.body.removeChild(el);
- }
- $(function() {
- //-----------------------------------------------------------
- // Artist Name
- var artistName = $(".thin h2").text();
- artistName = artistName.substr(artistName.indexOf(' ')+1);
- artistName = artistName.substr(0, artistName.indexOf(' -'));
- // Album Name
- var origName;
- if ($(".thin > h3").text().indexOf("-") > 0) {
- origName = $(".thin > h3").text();
- origName = origName.substr(origName.indexOf('-')+2).slice(0, -1);
- } else {
- origName = $(".thin h2").text();
- origName = origName.substr(origName.indexOf('-')+2);
- origName = origName.substr(0, origName.indexOf(' ['));
- }
- // Release Date
- var rlsDate = $(".thin h2").text();
- rlsDate = rlsDate.substr(rlsDate.indexOf(' [')+1);
- // Replace original title with fixed title
- var artistURL = $(".thin h2 a").attr("href"); // Fetch the artist URL before replacing the line
- $(".thin h2").html('<a href="'+ artistURL + '">' + artistName + '</a> - ' + origName + ' ' + rlsDate);
- $(".thin > h3").hide(); // Might as well hide the original title
- // Automatically copy formatted folder name to clipboard on download
- $(".group_torrent a").click(function() {
- var folderName = artistName + " - " + origName + " " + rlsDate;
- // Check what format it is from a list of known formats, and append to name
- var fileFormat = $(this).parent().parent().children("a").text();
- if (fileFormat.indexOf("MP3") > 0 && fileFormat.indexOf("320") > 0) {
- folderName += " [MP3]";
- } else if (fileFormat.indexOf("MP3") > 0 && fileFormat.indexOf("V0") > 0) {
- folderName += " [MP3 V0]";
- } else if (fileFormat.indexOf("FLAC") > 0) {
- folderName += " [FLAC]";
- } else if (fileFormat.indexOf("AAC") > 0 && fileFormat.indexOf("320") > 0) {
- folderName += " [AAC 320]";
- } else if (fileFormat.indexOf("AAC") > 0 && fileFormat.indexOf("256") > 0) {
- folderName += " [AAC 256]";
- }
- // Copy it to the clipboard
- console.log(folderName);
- copyToClipboard(folderName);
- });
- //-----------------------------------------------------------
- })
Advertisement
Add Comment
Please, Sign In to add comment