sidonath (owner)

Revisions

  • 896527 sidonath Thu Jan 29 04:43:26 -0800 2009
gist: 54522 Download_button fork
public
Public Clone URL: git://gist.github.com/54522.git
Embed All Files: show embed
one-click-paste-tasteometer.user.js #
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
// ==UserScript==
// @name last.fm One-click paste Taste-O-Meter
// @namespace http://z3c.info/
// @description Inserts results of Teste-O-Meter between you and the last user who replied on the same topic
// @include http://www.last.fm/group/*/forum/*
// @include http://www.lastfm.*/group/*/forum/*
// ==/UserScript==
 
//
// As the code below demonstrates I love chaining function calls :)
//
 
$ = unsafeWindow.$;
$$ = unsafeWindow.$$;
uwd = unsafeWindow.document;
 
function getUserTasteOMaticUrl() {
  return $$("a[name='last']")[0]
          .next()
          .select(".userName a")[0]
          .href + "/tasteomatic";
}
 
function insertTasteOMaticResults(details) {
  $("message").insert(
    details.responseText
      .replace(/<strong.*?>/g, '[b]')
      .replace(/<\/strong>/g, '[/b]')
      .replace(/<a.*?>/g, '[artist]')
      .replace(/<\/a>/g, '[/artist]')
      .replace(/<.*?>/g, '')
      .replace(/^\s+/g, '')
      .replace(/\s+$/g, '')
      .replace(/[ \t]+/g, ' ')
      .replace(/\n[ \t]+/g, '\n')
      .replace(/\n\n+/g, '\n\n')
  );
}
 
function requestTaste(event) {
  GM_xmlhttpRequest({
    method: "GET",
    url: getUserTasteOMaticUrl(),
    headers: {
      "User-Agent":"Greasemokey script",
      "Accept":"text/monkey,text/xml",
    },
    onload: insertTasteOMaticResults
  });
}
 
$$("#bbbuttons ul:first-child")[0].insert(
  $(uwd.createElement("li"))
    .writeAttribute("id", "texttaste")
    .addClassName("lfm")
    .writeAttribute("title", "Taste comparison")
    .insert(
      $(uwd.createElement("span"))
        .insert("Taste-o-meter")
        .observe("click", function () {
          setTimeout(requestTaste, 0);
        })
    )
);