Improve 8bcDump

Improve 2xAA's 8bcdump site (non-ID3 mode), adding a last played list and emboldening the currently playing song.

目前為 2017-03-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Improve 8bcDump
// @namespace   Improve8bcDump
// @description Improve 2xAA's 8bcdump site (non-ID3 mode), adding a last played list and emboldening the currently playing song.
// @include     http://brkbrkbrk.com/8bcdump/
// @version     0.1
// @grant       none
// ==/UserScript==

(function() {
  // The currently playing song should appear bold in list views.
  // .playing is a single <li> in the list of all songs.
  // .lastPlayed is an <ol> containing the last played songs.
  
  var styleEl = document.createElement('style');
  styleEl.innerHTML  = '.playing, .lastPlayed li:first-child { font-weight: bold; }';
  styleEl.innerHTML += '.playing:after, .lastPlayed li:first-child:after { content: " (playing)" }';
  document.body.appendChild(styleEl);
  
  // Create a queue for the last played songs.
  // The queue is realized in an <ol>, contained in parentElement.
  
  function LastPlayedList(maxLength, parentElement) {
    // Create a heading for the last played list
    var heading = document.createElement('h2');
    heading.textContent = 'Last played';
    parentElement.appendChild(heading);
    
    // Create the list itself
    var list = document.createElement('ol');
    list.className = 'lastPlayed';
    parentElement.appendChild(list);
    
    // Push songs through the stack
    this.push = function(song) {
      var nodes = list.childNodes;
      
      if (nodes.length == maxLength) {
        list.removeChild(nodes[nodes.length - 1]);
      }
      
      var newItem = document.createElement('li');
      newItem.textContent = song;
      
      list.insertBefore(newItem, nodes[0]);
    }
  }
  
  // Create a list at the bottom of the page to hold the last 10 songs
  var lastPlayedDiv = document.createElement('div');
  document.body.appendChild(lastPlayedDiv);
  
  var lastPlayedList = new LastPlayedList(10, lastPlayedDiv);
  
  // The player at the bottom of the page
  // should also show the filename when playing songs.
  
  var updateID3_super = window.updateID3;
  
  // Override the existing updateID3 method
  
  window.updateID3 = function(id3) {
    updateID3_super(id3);
    
    var url = document.querySelector('li.playing a').href;
    var urlParts = decodeURIComponent(url).split('/');
    var filename = urlParts.pop();
    
    var liID3 = document.querySelector('li.id3 ');
    liID3.textContent += ', Filename: ' + filename;
    
    // Add the current song to the last played list
    lastPlayedList.push(liID3.textContent);
  }
  
}());