Refresh/Clear NBViewer Cache

Add a button to navigation bar to refresh/clear the cache of nbviewer by appending "?flush_cache=true" to the url

当前为 2017-05-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Refresh/Clear NBViewer Cache
  3. // @namespace Peijun Zhu
  4. // @description Add a button to navigation bar to refresh/clear the cache of nbviewer by appending "?flush_cache=true" to the url
  5. // @include http://nbviewer.jupyter.org/github/*
  6. // @version 2.4
  7. // @grant none
  8. // ==/UserScript==
  9. function flush() {
  10. var url = document.location.href;
  11. while (url.substr( - 1) === '/' || url.substr( - 1) === '#') {
  12. //Strip # or / in the end
  13. url = url.substr(0, url.length - 1);
  14. }
  15. var tail = '?flush_cache=true';
  16. if (!url.endsWith(tail)) {
  17. document.location.href = url + tail;
  18. }
  19. else {
  20. document.location.reload();
  21. }
  22. }
  23. function add_flush_button() {
  24. var lu = document.getElementsByClassName('nav navbar-nav navbar-right') [0];
  25. var li = document.createElement('li');
  26. var a = document.createElement('a');
  27. li.appendChild(a);
  28. lu.appendChild(li);
  29. a.href = '#';
  30. a.onclick = flush;
  31. a.innerHTML = 'Flush';
  32. }
  33. add_flush_button();