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. var currentContent;
  19.  
  20. if (typeof angular !== 'undefined' || typeof angular.element('#LibraryContent').scope() !== 'undefined') {
  21. setwatcher();
  22. window.addEventListener("hashchange", setwatcher);
  23. document.addEventListener('keydown', function(e) {
  24. if ('card' === currentContent) {
  25. // pressed ctrl+alt+c
  26. if (e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
  27. GM_setClipboard('<a href="url">test</a>','html');
  28. }
  29. } else if ('list' === currentContent) {
  30. // pressed ctrl+alt+c
  31. if (e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
  32. GM_setClipboard(getlisthtml(),'html');
  33. }
  34. }
  35. }, false);
  36. }
  37.  
  38. function setwatcher() {
  39. currentContent = null;
  40. var i;
  41. if (!i) i = 50;
  42. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1))) {
  43. // only cards set $root.loading, poll loading
  44. loadingWatcher = setInterval(checkloading, i);
  45. } else {
  46. i = 1000;
  47. loadingWatcher = setInterval(function (){
  48. clearInterval(loadingWatcher);
  49. loaded();
  50. }, i);
  51. }
  52. //console.log('i=' + i);
  53. }
  54. function checkloading() {
  55. //console.log('watch');
  56. //console.log(angular.element('#LibraryContent').scope().$root.loading);
  57.  
  58. if (angular.element('#LibraryContent').scope().$root.loading !== true) {
  59. //console.log(typeof angular.element('#LibraryContent').scope().$root.loading);
  60. clearInterval(loadingWatcher);
  61. loaded();
  62. }
  63. }
  64.  
  65. function loaded () {
  66. console.log('loaded');
  67. //console.log($('#LibraryContent').html());
  68.  
  69. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1)) && $('#LibraryContent').find('article.LearningCard:visible').length > 0) {
  70. //console.log('card');
  71. currentContent = 'card';
  72. }
  73. if ($('#LibraryContent').find('#LibraryList:visible').length > 0) {
  74. //console.log('list');
  75. currentContent = 'list';
  76.  
  77. }
  78. }
  79.  
  80. function getParameterByName(name, url) {
  81. if (!url) url = window.location.href;
  82. name = name.replace(/[\[\]]/g, "\\$&");
  83. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  84. results = regex.exec(url);
  85. if (!results) return null;
  86. if (!results[2]) return '';
  87. return decodeURIComponent(results[2].replace(/\+/g, " "));
  88. }
  89.  
  90. function getlisthtml() {
  91. var html = '';
  92. html += '<h2>' + $.trim($('#LibraryContent').find('#Title').text()) + '</h2>';
  93. var tempDiv = $('<div>').append($('table#LibraryList').clone().find('td:not(:nth-child(2), :nth-child(3), :nth-child(8), :nth-child(9))').remove().end().find('th').remove().end());
  94. tempDiv.hide();
  95. $('body').append(tempDiv);
  96. $(tempDiv).find('a').each(function(i, anchor){
  97. anchor.href = $(anchor).prop('href'); // all urls to abs
  98. })
  99. html += $('table#LibraryList').html();
  100. tempDiv.remove();
  101. tempDiv = null;
  102. return html;
  103. }
  104.  
  105. }());