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.4
  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. if ((e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) || (e.key == 'F9' && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey)) {
  26. // pressed ctrl+alt+c or F9
  27. GM_setClipboard(getcardhtml(),'html');
  28. } else if (e.key == 'a' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
  29. // pressed ctrl+alt+a
  30. GM_setClipboard(getcardhtml(true),'html');
  31. }
  32. } else if ('list' === currentContent) {
  33. if (e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
  34. // pressed ctrl+alt+c
  35. GM_setClipboard(getlisthtml(),'html');
  36. }
  37. }
  38. }, false);
  39. }
  40.  
  41. function setwatcher() {
  42. currentContent = null;
  43. var i;
  44. if (!i) i = 50;
  45. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1))) {
  46. // only cards set $root.loading, poll loading
  47. loadingWatcher = setInterval(checkloading, i);
  48. } else {
  49. i = 1000;
  50. loadingWatcher = setInterval(function (){
  51. clearInterval(loadingWatcher);
  52. loaded();
  53. }, i);
  54. }
  55. //console.log('i=' + i);
  56. }
  57. function checkloading() {
  58. //console.log('watch');
  59. //console.log(angular.element('#LibraryContent').scope().$root.loading);
  60.  
  61. if (angular.element('#LibraryContent').scope().$root.loading !== true) {
  62. //console.log(typeof angular.element('#LibraryContent').scope().$root.loading);
  63. clearInterval(loadingWatcher);
  64. loaded();
  65. }
  66. }
  67.  
  68. function loaded () {
  69. //console.log('loaded');
  70. //console.log($('#LibraryContent').html());
  71.  
  72. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1)) && $('#LibraryContent').find('article.LearningCard:visible').length > 0) {
  73. //console.log('card');
  74. currentContent = 'card';
  75. }
  76. if ($('#LibraryContent').find('#LibraryList:visible').length > 0) {
  77. //console.log('list');
  78. currentContent = 'list';
  79.  
  80. }
  81. }
  82.  
  83. function getParameterByName(name, url) {
  84. if (!url) url = window.location.href;
  85. name = name.replace(/[\[\]]/g, "\\$&");
  86. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  87. results = regex.exec(url);
  88. if (!results) return null;
  89. if (!results[2]) return '';
  90. return decodeURIComponent(results[2].replace(/\+/g, " "));
  91. }
  92.  
  93. function getcardhtml(full) {
  94. var html = '';
  95. html += '<h1>' + $.trim($('article.LearningCard h1:first').clone().children().remove().end().text())
  96. + ($('article.LearningCard h1:first').attr('tooltip-content')? (' (' + $('article.LearningCard h1:first').attr('tooltip-content').replace(/^(Synonyme:<br> )/,'') + ')') : '')
  97. + '</h1>';
  98. var tempDiv;
  99. if (full) {
  100. tempDiv = $('<div>').append($('article.LearningCard>section').clone().find('section').remove().end());
  101. } else {
  102. tempDiv = $('<div>').append($('article.LearningCard>section:first p').clone());
  103. }
  104. tempDiv.find('a').each(function(i, anchor){
  105. anchor.href = $(anchor).prop('href'); // all urls to abs
  106. })
  107. html += tempDiv.html();
  108. tempDiv.remove();
  109. tempDiv = null;
  110. return html;
  111. }
  112.  
  113. function getlisthtml() {
  114. var html = '';
  115. html += '<h2>' + $.trim($('#LibraryContent').find('#Title').text()) + '</h2>';
  116. 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());
  117. //tempDiv.hide();
  118. //$('body').append(tempDiv);
  119. tempDiv.find('a').each(function(i, anchor){
  120. anchor.href = $(anchor).prop('href'); // all urls to abs
  121. })
  122. html += tempDiv.html();
  123. tempDiv.remove();
  124. tempDiv = null;
  125. return html;
  126. }
  127.  
  128. }());