-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpinboard-manager.html
155 lines (125 loc) · 4.83 KB
/
pinboard-manager.html
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
<html>
<head>
<script type="text/javascript">
var urlBase = "https://@api.pinboard.in/v1/tags/";
var req, tags, timer, output, username;
function loadXMLDoc() {
req = false;
req = new XMLHttpRequest();
if(req) {
req.onreadystatechange = processReqChange;
req.open("GET", urlBase + 'get', true);
req.send("");
}
}
var nodesArray;
function processReqChange() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
document.write("<p><a href='javascript:scheduleUpdates();'>UPDATE CHANGED TAGS</a></p>");
document.write("<table cellpadding=3>");
document.write("<tr style='background-color:#ccc;'><td align='right'>EXISTING TAG</td><td>COUNT</td><td>REPLACE WITH/FOLD INTO...</td></tr>")
////////////////////////////////////////////////////////////
// Sort alphabetical by tag name
////////////////////////////////////////////////////////////
tags = Array.prototype.slice.call(req.responseXML.getElementsByTagName("tag"))
tags.sort(function(a, b) {
return (a.getAttribute('tag').toLowerCase() < b.getAttribute('tag').toLowerCase() ? -1 : 1);
return 0; // if they're equal
});
for (var i = 0; i < tags.length; i++) {
document.write("<tr>");
document.write("<td align='right' id='origtag" + i + "'>");
document.write("<a href='javascript:openUsersTagsPage(" + i + ")'>")
document.write(tags[i].getAttribute("tag"));
document.write("</a>")
document.write("</td>");
document.write("<td align='right' bgcolor='#ccc'>");
document.write(tags[i].getAttribute("count"));
document.write("</td>");
document.write("<td>");
//document.write("<input id='newtag" + i + "' type=text size=50 value='" + tags[i].getAttribute("tag").replace(/[+_]/g, '-') + "' />");
document.write("<input id='newtag" + i + "' type=text size=50 value='" + tags[i].getAttribute("tag") + "' />");
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
document.write("<div id='output' style='position:absolute; top:10px; left:700px; background-color:#ccc;'><div>")
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
function scheduleUpdates() {
outputWrite("Please be patient... each change takes about 2 seconds, to comply with the PinBoard terms of service.", true);
timer = setInterval(processNextUpdate, 2000);
}
function submitChange(url) {
req = false;
req = new XMLHttpRequest();
if(req) {
req.onreadystatechange = processChangeResp;
req.open("GET", url, true);
req.send("");
}
}
function processChangeResp() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
outputWrite("...completed: " + req.statusText);
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
function openUsersTagsPage(i) {
if (username == null) {
username = window.prompt("Please enter your PinBoard username. Your username is not stored. You'll be asked for it once each time you reload this bulk manager page and click a tag. Your PinBoard username is required to construct your user-specific URL to view your tagged bookmarks (e.g., https://pinboard.in/u:someuser/t:sometag/):", "");
}
tagName = document.getElementById('origtag' + i).innerText;
usersTagsURL = "https://pinboard.in/u:" + username + "/t:" + encodeURIComponent(tagName) + "/";
//console.log(usersTagsURL);
window.open(usersTagsURL, "_blank");
}
function processNextUpdate() {
var i, changed;
i = 0;
changed = 0;
while ( (changed === 0) && (i < tags.length) ) {
origNode = document.getElementById('origtag' + i);
newNode = document.getElementById('newtag' + i);
// innerText rather than innerHTML because innerHTML("&") == "&"
origValue = origNode.innerText; // because it's a table cell;
newValue = newNode.value; // because it's a form field
if (origValue !== newValue) {
changed++;
origNode.innerHTML = newNode.value;
query = urlBase + "rename?old=" + encodeURIComponent(origValue) + "&new=" + encodeURIComponent(newValue);
outputWrite(origValue + ' ---> ' + newValue);
submitChange(query);
}
i++;
}
if (changed === 0) {
outputWrite("DONE");
clearInterval(timer);
}
}
function outputWrite(mesg, clear) {
output = document.getElementById("output");
if (clear === true) {
output.innerHTML = "<p>" + mesg + "</p>";
} else {
output.innerHTML += "<p>" + mesg + "</p>";
}
}
</script>
</head>
<body onload="javascript:loadXMLDoc()">
</body>
</html>