Improve 8bcDump

Improve the interface of the public 8bitcollective archive on brkbrkbrk.com.

当前为 2017-03-29 提交的版本,查看 最新版本

// ==UserScript==
// @name        Improve 8bcDump
// @namespace   Improve8bcDump
// @description Improve the interface of the public 8bitcollective archive on brkbrkbrk.com.
// @include     http://brkbrkbrk.com/8bcdump/
// @include     https://brkbrkbrk.com/8bcdump/
// @include     http://www.brkbrkbrk.com/8bcdump/
// @include     https://www.brkbrkbrk.com/8bcdump/
// @version     0.2
// @grant       none
// ==/UserScript==

(function() {
  console.log('Improve8bcDump v0.2 is active.');

  // Fix a wrong attribute on the page's stylesheet.
  var stylesheet = document.querySelector('link[type="text/stylesheet"]');
  stylesheet.setAttribute('type', 'text/css');

  // 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 newStyles = document.createElement('style');
  newStyles.textContent += '.playing, .lastPlayed li:first-child { font-weight: bold; }';
  newStyles.textContent += '.playing:after, .lastPlayed li:first-child:after { content: " (playing)" }';
  document.body.appendChild(newStyles);
  
  // Create a stack for the last played songs.
  // The stack 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,
  // and the song's information should be added to the last played list.
  
  // Override the existing updateID3 method
  
  window.updateID3 = function(id3) {
    var filename = document.querySelector('li.playing a').textContent;
    var songDesc = 'Title: ' + id3.title + ', Artist: ' + id3.artist + ', Album: ' + id3.album + ', Filename: ' + filename;
    
    window.liID3.textContent = songDesc;
    lastPlayedList.push(songDesc);
  }
}());