Amboss Copier

Copy article informations from Miamed Amboss.

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

  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.5
  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. if ((e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey)) {
  27. // pressed ctrl+alt+c or //F9
  28. GM_setClipboard(getcardhtml(),'html');
  29. } else if (e.key == 'a' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
  30. // pressed ctrl+alt+a
  31. GM_setClipboard(getcardhtml(true),'html');
  32. }
  33. } else if ('list' === currentContent) {
  34. if (e.key == 'c' && !e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
  35. // pressed ctrl+alt+c
  36. GM_setClipboard(getlisthtml(),'html');
  37. }
  38. }
  39. }, false);
  40. }
  41.  
  42. function setwatcher() {
  43. currentContent = null;
  44. var i;
  45. if (!i) i = 50;
  46. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1))) {
  47. // only cards set $root.loading, poll loading
  48. loadingWatcher = setInterval(checkloading, i);
  49. } else {
  50. i = 2000;
  51. loadingWatcher = setInterval(function (){
  52. clearInterval(loadingWatcher);
  53. loaded();
  54. }, i);
  55. }
  56. //console.log('i=' + i);
  57. }
  58. function checkloading() {
  59. //console.log('watch');
  60. //console.log(angular.element('#LibraryContent').scope().$root.loading);
  61.  
  62. if (angular.element('#LibraryContent').scope().$root.loading !== true) {
  63. //console.log(typeof angular.element('#LibraryContent').scope().$root.loading);
  64. clearInterval(loadingWatcher);
  65. loaded();
  66. }
  67. }
  68.  
  69. function loaded () {
  70. //console.log('loaded');
  71. //console.log($('#LibraryContent').html());
  72.  
  73. // TODO: Change title of kreuzen
  74. // https://amboss.miamed.de/study2/index#/aB123Cdef/45
  75. // $('<div/>').html($('[tooltip-classname="lg"]').attr('tooltip-content')).text().replace(/^(Sitzung: )/,'');
  76. // "Examens-Kreuzplan (H. 2016), Tag 12 (Frage 34 von 56)"
  77.  
  78. if (null !== getParameterByName('xid', '?' + window.location.hash.substring(1)) && $('#LibraryContent').find('article.LearningCard:visible').length > 0) {
  79. //console.log('card');
  80. currentContent = 'card';
  81. }
  82. if ($('#LibraryContent').find('#LibraryList:visible').length > 0) {
  83. //console.log('list');
  84. currentContent = 'list';
  85. getListTitle(); // change browser window title if proper
  86. }
  87. }
  88.  
  89. function getcardhtml(full) {
  90. var html = '';
  91. html += '<h1>' + $.trim($('article.LearningCard h1:first').clone().children().remove().end().text())
  92. + ($('article.LearningCard h1:first').attr('tooltip-content')? (' (' + $('article.LearningCard h1:first').attr('tooltip-content').replace(/^(Synonyme:<br> )/,'') + ')') : '')
  93. + '</h1>';
  94. var tempDiv;
  95. if (full) {
  96. tempDiv = $('<div>').append($('article.LearningCard>section').clone().find('section, .unwichtig, .veraltet').remove().end().find('li:emptyorspace').remove().end()); // remove meta infos, veraltet and unwichtig
  97. //.find('ul:visible:empty, ol:visible:empty').remove().end()
  98. //.find('ul:empty, ol:empty').remove().end()
  99. } else {
  100. tempDiv = $('<div>').append($('article.LearningCard>section:first p').clone()); // only p extracted, first section without p probably not abstracts
  101. }
  102. tempDiv.find('a').each(function(i, anchor){
  103. anchor.href = $(anchor).prop('href'); // all urls to abs
  104. })
  105. html += tempDiv.html();
  106. tempDiv.remove();
  107. tempDiv = null;
  108. return html;
  109. }
  110.  
  111. function getlisthtml() {
  112. var html = '';
  113. var listTitle = getListTitle();
  114. html += '<h2>' + listTitle + '</h2>';
  115. 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());
  116. //tempDiv.hide();
  117. //$('body').append(tempDiv);
  118. tempDiv.find('a').each(function(i, anchor){
  119. anchor.href = $(anchor).prop('href'); // all urls to abs
  120. })
  121. html += tempDiv.html();
  122. tempDiv.remove();
  123. tempDiv = null;
  124. return html;
  125. }
  126.  
  127. function getListTitle() {
  128. var listTitle = $.trim($('#LibraryContent').find('#Title').text());
  129. var examDay = $.trim($('div.Tab.active li.result-selected').text());
  130. var checkStr = examDay ? $.trim(examDay.substring(0,6)).toUpperCase() : ''; // 'Tag 1 ' or 'Tag 99' => 'TAG 1' or 'TAG 99'
  131. if (examDay && checkStr.length > 2 && listTitle.substr(-checkStr.length) === checkStr) {
  132. listTitle = examDay;
  133. document.title = listTitle;
  134. }
  135. else if ('TOP-100 LERNKARTEN' === listTitle) {
  136. listTitle = 'Top-100 Lernkarten';
  137. document.title = listTitle;
  138. }
  139. return listTitle;
  140. }
  141.  
  142. function getParameterByName(name, url) {
  143. if (!url) url = window.location.href;
  144. name = name.replace(/[\[\]]/g, "\\$&");
  145. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  146. results = regex.exec(url);
  147. if (!results) return null;
  148. if (!results[2]) return '';
  149. return decodeURIComponent(results[2].replace(/\+/g, " "));
  150. }
  151.  
  152. $.expr[':'].notext = function detectNoText(x){
  153. return x.innerHTML && x.innerHTML.replace(/(<!--.*(?!-->))|\s+/g, '').length === 0
  154. }
  155.  
  156. $.expr[':'].emptyorspace = function detectNoText(x){
  157. return x.innerHTML.replace(/(<!--.*(?!-->))|\s+/g, '').length === 0
  158. }
  159.  
  160. }());