Refresh NBViewer Button

Add a button to navigation bar to flush the cache of nbviewer

当前为 2016-10-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Refresh NBViewer Button
  3. // @namespace Peijun Zhu
  4. // @description Add a button to navigation bar to flush the cache of nbviewer
  5. // @include http://nbviewer.jupyter.org/github/*
  6. // @version 2
  7. // @grant none
  8. // ==/UserScript==
  9. function flush() {
  10. var url = window.location.href;
  11. if (url.substr( - 1) === '/') {
  12. url = url.substr(0, url.length - 1);
  13. }
  14. var tail = '?flush=true';
  15. if (!url.endsWith(tail)) {
  16. window.location.href = url + tail;
  17. }
  18. return;
  19. }
  20.  
  21. function add_flush_button() {
  22. //lu->li->a->input->button->flush()
  23. var lu = document.getElementsByClassName('nav navbar-nav navbar-right') [0];
  24. var li=document.createElement('li');
  25. var a=document.createElement('a');
  26. li.appendChild(a);
  27. lu.appendChild(li);
  28. var input = document.createElement('input');
  29. input.type = 'button';
  30. input.value = 'Flush';
  31. input.onclick = flush;
  32. a.appendChild(input);
  33. }
  34. add_flush_button();