Amboss Copier

Copy article informations from Miamed Amboss.

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

  1. // ==UserScript==
  2. // @name Amboss Copier
  3. // @namespace http://oix.cc/gm
  4. // @description Copy article informations from Miamed Amboss.
  5. // @author Bin Zhang
  6. // @icon https://amboss.miamed.de/favicon-192x192.png
  7. // @homepageURL http://oix.cc/amboss
  8. // @version 0.0.3
  9. // @match https://amboss.miamed.de/library
  10. // @include /^https?://amboss-miamed-de\.ezproxy\..*/library$/
  11. // @grant GM_setClipboard
  12. // @run-at document-idle
  13. // ==/UserScript==
  14.  
  15. (function(){
  16.  
  17. var loadingWatcher;
  18.  
  19. if (typeof angular !== 'undefined' || typeof angular.element('#LibraryContent').scope() !== 'undefined') {
  20. setwatcher();
  21. window.addEventListener("hashchange", setwatcher);
  22. }
  23.  
  24. function setwatcher() {
  25. var i;
  26. if (!i) i = 50;
  27. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1))) {
  28. // only cards set $root.loading, poll loading
  29. loadingWatcher = setInterval(checkloading, i);
  30. } else {
  31. i = 1000;
  32. loadingWatcher = setInterval(function (){
  33. clearInterval(loadingWatcher);
  34. loaded();
  35. }, i);
  36. }
  37. //console.log('i=' + i);
  38. }
  39. function checkloading() {
  40. //console.log('watch');
  41. //console.log(angular.element('#LibraryContent').scope().$root.loading);
  42.  
  43. if (angular.element('#LibraryContent').scope().$root.loading !== true) {
  44. //console.log(typeof angular.element('#LibraryContent').scope().$root.loading);
  45. clearInterval(loadingWatcher);
  46. loaded();
  47. }
  48. }
  49.  
  50. function loaded () {
  51. //console.log('loaded');
  52. //console.log($('#LibraryContent').html());
  53.  
  54. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1)) && $('#LibraryContent').find('article.LearningCard:visible').length > 0) {
  55. //console.log('card');
  56. }
  57. if ($('#LibraryContent').find('#LibraryList:visible').length > 0) {
  58. //console.log('list');
  59. document.addEventListener('keydown', function(e) {
  60. // pressed ctrl+alt+c
  61. if (e.keyCode == 99 && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
  62. GM_setClipboard('<a href="url">test</a>','html');
  63. }
  64. }, false);
  65. }
  66. }
  67.  
  68. function getParameterByName(name, url) {
  69. if (!url) url = window.location.href;
  70. name = name.replace(/[\[\]]/g, "\\$&");
  71. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  72. results = regex.exec(url);
  73. if (!results) return null;
  74. if (!results[2]) return '';
  75. return decodeURIComponent(results[2].replace(/\+/g, " "));
  76. }
  77.  
  78. }());