Workflowy Sort

Alphabetically sort open lists in workflowy

当前为 2018-03-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Workflowy Sort
  3. // @namespace https://workflowy.com
  4. // @version 0.1
  5. // @description Alphabetically sort open lists in workflowy
  6. // @author Roland
  7. // @match https://workflowy.com
  8. // @run-at document-idle
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // On page load, listen for bullets to populate, then sort them
  16. var bulletLoaded = setInterval(function(){
  17. console.log('checking bullets');
  18. if( document.getElementById('loadingScreen').style.display === 'none' ) {
  19. console.log('bullets loaded!');
  20. sortBullets();
  21. clearInterval(bulletLoaded);
  22. }
  23. }, 200);
  24.  
  25. // sort bullets on click events (bullet expansion and clicking into a bullet)
  26. document.addEventListener ("mousedown", autoSort);
  27.  
  28. // sort bullets on hotkey press (Ctrl+Shift+S by default)
  29. document.addEventListener('keydown', keyDownSortBullets);
  30.  
  31. function autoSort() {
  32. $(".bullet, a.content, #expandButton").unbind();
  33. $('.bullet, a.content').click(function(event){
  34. setTimeout(function(){
  35. sortBullets();
  36. console.log('bullet sort');
  37. }, 250);
  38. });
  39. $('#expandButton').click(function(event){
  40. // if($(this).attr('data-open-on-last-click') === "true" || typeof $(this).attr('data-open-on-last-click') === 'undefined'){
  41. setTimeout(function(){
  42. sortBullets();
  43. console.log('expand sort');
  44. }, 50);
  45. // }
  46. });
  47.  
  48. }
  49.  
  50. function sortBullets() {
  51. jQuery.fn.sortDomElements = (function() {
  52. return function(comparator) {
  53. return Array.prototype.sort.call(this, comparator).each(function(i) {
  54. this.parentNode.appendChild(this);
  55. });
  56. };
  57. })();
  58. $('div.children').children('.project').sortDomElements(function(a,b){
  59. var akey = $(a).children('.name').children('.content').text().toLowerCase();
  60. var bkey = $(b).children('.name').children('.content').text().toLowerCase();
  61. if (akey == bkey) return 0;
  62. if (akey < bkey) return -1;
  63. if (akey > bkey) return 1;
  64. });
  65. return true;
  66. }
  67.  
  68. function keyDownSortBullets(e) {
  69. if(e.ctrlKey && e.shiftKey && e.keyCode === 83){
  70. e.preventDefault();
  71. console.log('sorting...');
  72. sortBullets();
  73. return false;
  74. //saveAll();
  75. }
  76. }
  77. })();