github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

dwo / Songkick-SetlistHelper

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (1)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Greasemonkey UserScript to make adding setlists to Songkick easier — Read more

  cancel

http://userscripts.org/scripts/show/58635

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

added link to userscripts in README 
dwo (author)
Mon Sep 28 14:06:59 -0700 2009
commit  be09b0cef8efabffb7946771c9230e85b5f53f80
tree    16c98ca2ff85f8025cc561fcb624d7ff3a52814e
parent  f5089bd8059a6795df50f3168ceb616f854ab94c
Songkick-SetlistHelper / songkicksetlist.user.js songkicksetlist.user.js
100644 235 lines (201 sloc) 7.262 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Songkick SetlistHelper
// version 0.1 BETA!
// 2009-09-20
// Copyright (c) 2009, Robin Tweedie (robin.tweedie@gmail.com)
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This script adds a textarea to the Songkick setlist interface.
// You can paste a newline separated setlist into the textarea and
// initiate parsing of the setlist into the form with the "parse tracks"
// button. You can also tick whether you would like common numbering
// formats removed from the beginning of the track names.
//
// Uses jQuery (http://jquery.com/)
//
// Future plans:
// * support for parsing encores (have to be done manually for now)
// * refactor to move functions out of global scope
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Songkick SetlistHelper
// @namespace http://songkick.com
// @description Makes adding setlists to Songkick.com easier
// @include http://www.songkick.com/*/setlists/*
// ==/UserScript==
 
/*jslint white: true, onevar: true, browser: true, nomen: true,
eqeqeq: true, plusplus: true, bitwise: true, regexp: true,
newcap: true, immed: true */
 
/* To Title Case 1.1.1
* David Gouch <http://individed.com>
* 23 May 2008
* License: http://individed.com/code/to-title-case/license.txt
*
* In response to John Gruber's call for a Javascript version of his script:
* http://daringfireball.net/2008/05/title_case
*/
String.prototype.toTitleCase = function () {
    return this.replace(/([\w&`'‘’"“.@:\/\{\(\[<>_]+-? *)/g, function (match, p1, index, title) {
        if (index > 0 && title.charAt(index - 2) !== ":" &&
         match.search(/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\.?|via)[ \-]/i) > -1) {
            return match.toLowerCase();
        }
        if (title.substring(index - 1, index + 1).search(/['"_{(\[]/) > -1) {
            return match.charAt(0) + match.charAt(1).toUpperCase() + match.substr(2);
        }
        if (match.substr(1).search(/[A-Z]+|&|[\w]+[._][\w]+/) > -1 ||
         title.substring(index - 1, index + 1).search(/[\])}]/) > -1) {
            return match;
        }
        return match.charAt(0).toUpperCase() + match.substr(1);
    });
};
 
/**
* Strips several common forms of numbering & whitespace from the
* front of a string using a regular expression
* examples that would be stripped: 1) #2 3. 4: 5
* @param string input_string
* @return string
*/
String.prototype.stripNumbers = function () {
    return this.replace(/^(\s*[#\d\.:\)]*\s*)/i, '');
};
 
/**
* @param string prefix
* @param int id
* @return jQuery
*/
function create_track_input(prefix, id) {
    var new_item = $("<dd></dd>"),
        new_input = $("<input type='text' />"),
        prev_id = id - 1;
        
    new_input.attr("id", prefix + id);
    new_input.attr("name", prefix + id);
    new_input.addClass("text");
    
    new_item.append(new_input);
    
    //append new song to list in appropriate place
    $("#" + prefix + prev_id).parent().after(new_item);
        
    return new_input; //return jQuery object of new input
}
 
/**
* @param string input_string raw pasted text
* @param array opts list of true/false options for parsing
* @return array
*/
function parse_tracks(input_string, opts) {
    var i,
        track_array = input_string.split("\n");
    
    //iterate over parsed tracks
    for (i = 0; i < track_array.length; i = i + 1) {
        //strip numbering
        if (opts.stripNumbers) {
            track_array[i] = track_array[i].stripNumbers();
        }
        
        //remove track if blank
        if (track_array[i].length === 0) {
            track_array.splice(i, 1);
            i = i - 1;
            continue;
        }
        
        //title casing
        if (opts.titleCase) {
            track_array[i] = track_array[i].toTitleCase();
        }
    }
    
    return track_array;
}
 
/**
* @param string prefix
* @param array track_array
* @return int
*/
function insert_tracks(prefix, track_array) {
    var i, track_input;
    
    for (i = 0; i < track_array.length; i = i + 1) {
        track_input = $("#" + prefix + i);
    
        //create a new input field if it doesn't already exist
        if (track_input.length !== 1) {
            track_input = create_track_input(prefix, i);
        }
        
        track_input.val(track_array[i]);
    }
    
    return i;
}
 
/**
* Fetch parsing options from list of checkboxes and return
* as key-value pairs object.
* @return object
*/
function get_options() {
    var i,
        checkboxes = $("dd#parseopts input"),
        opts = {};
    
    for (i = 0; i < checkboxes.length; i = i + 1) {
        opts[checkboxes[i].id] = checkboxes[i].checked;
    }
    
    return opts;
}
 
/**
* go button click event handling
*/
var onGoClick = function () {
    var sl_paste = $("#sl_paste"),
        track_text = sl_paste.val(),
        parse_opts = get_options(),
        prefix = this.id;
        
    //insert tracks by parsing from paste area, taking number stripping option into account
    insert_tracks(prefix, parse_tracks(track_text, parse_opts));
    sl_paste.val('');
};
 
function generate_option(id, label) {
    var html = "<input id='" + id + "' type='checkbox' />&nbsp;" + label;
    return html;
}
 
/**
* Start injecting HTML and adding event listeners.
*/
function init() {
    var html = {};
    html.deflist = $("div.fieldset dl:first");
    
    html.ta_label = $("<dt><label>Paste setlist here</label></dt>");
    html.deflist.prepend(html.ta_label);
    
    html.pa_dd = $("<dd></dd>");
    
    html.paste_area = $("<textarea id='sl_paste'></textarea>");
    html.paste_area.css({"width": "180px", "height": "130px"});
    html.pa_dd.append(html.paste_area);
    html.ta_label.after(html.pa_dd);
    
    html.cleanopts_label = $("<dt><label>Parsing options</label></dt>");
    html.pa_dd.after(html.cleanopts_label);
    
    html.clean_optlist = $("<dd id='parseopts'></dd>");
    html.clean_optlist.append(generate_option("stripNumbers", "Remove numbering from beginning of track names"));
    html.clean_optlist.append("<br />");
    html.clean_optlist.append(generate_option("titleCase", "Convert tracks to Title Case"));
    html.cleanopts_label.after(html.clean_optlist);
    
    html.parse_dd = $("<dd></dd>");
    html.parse_btn = $("<input id='main_track_' class='submit button' type='button' value='Parse tracks' />");
    //add click event handler to Go button
    html.parse_btn.click(onGoClick);
    html.parse_dd.append(html.parse_btn);
    
    html.clean_optlist.after(html.parse_dd);
}
 
/**
* Recusively checks for jQuery to be loaded.
*/
function GM_wait() {
    if (typeof unsafeWindow.jQuery === 'undefined') {
        window.setTimeout(GM_wait, 100);
    } else {
        $ = unsafeWindow.jQuery;
        init();
    }
}
 
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://code.jquery.com/jquery-latest.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
var GM_start = new GM_wait();
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server