User:Quarl/watchbutton.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// [[User:Quarl/watchbutton.js]] - change standard watch/unwatch tab to be // asynchronous. // quarl 2006-02-03 initial version // requires: wikiwatch.js, util.js // <pre><nowiki> var watchbutton = new Object(); watchbutton.toggleAsync = function() { if (watchbutton.currentlyWatched) { wikiwatch.unwatchAsync(wikiPage, watchbutton._wuwSuccess, watchbutton.tab); } else { wikiwatch.watchAsync(wikiPage, watchbutton._wuwSuccess, watchbutton.tab); } return false; } watchbutton._wuwSuccess = function() { watchbutton.currentlyWatched = !watchbutton.currentlyWatched; if (watchbutton.currentlyWatched) { watchbutton.link.innerHTML = 'Unwatch'; watchbutton.link.href = wikiPage.qurl + '&action=unwatch'; watchbutton.link.title = 'Remove this page from your watchlist'; } else { watchbutton.link.innerHTML = 'Watch'; watchbutton.link.href = wikiPage.qurl + '&action=watch'; watchbutton.link.title = 'Add this page to your watchlist'; } } watchbutton._load = function() { var tab_unwatch = document.getElementById('ca-unwatch'); if (tab_unwatch) { watchbutton.currentlyWatched = true; watchbutton.tab = tab_unwatch; } var tab_watch = document.getElementById('ca-watch'); if (tab_watch) { watchbutton.currentlyWatched = false; watchbutton.tab = tab_watch; } if (!watchbutton.tab) return; watchbutton.link = watchbutton.tab.getElementsByTagName('a')[0]; watchbutton.link.onclick = watchbutton.toggleAsync; } addOnloadHook(watchbutton._load); // </nowiki></pre>

