forked from WilDoane/Pinboard-Bulk-Tag-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinboard-manager.html
131 lines (105 loc) · 3.6 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
<html>
<head>
<script type="text/javascript">
var urlBase = "https://@api.pinboard.in/v1/tags/";
var req, tags, timer, output;
function loadXMLDoc() {
req = false;
req = new XMLHttpRequest();
if(req) {
req.onreadystatechange = processReqChange;
req.open("GET", urlBase + 'get', true);
req.send("");
}
}
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>")
tags = req.responseXML.getElementsByTagName("tag");
for (var i = 0; i < tags.length; i++) {
document.write("<tr>");
document.write("<td align='right' id='origtag" + i + "'>");
document.write(tags[i].getAttribute("tag"));
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 processNextUpdate() {
var i, changed;
i = 0;
changed = 0;
while ( (changed === 0) && (i < tags.length) ) {
origNode = document.getElementById('origtag' + i);
newNode = document.getElementById('newtag' + i);
origValue = origNode.innerHTML; // 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>