Advertisement
Guest User

Untitled

a guest
Aug 13th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2.  
  3.         var widget_array = {
  4.             'RELATED_TAGS' : {
  5.                 'old_find' : 'div#related-tags, .module.js-gps-related-tags',
  6.                 'icon_path' : 'M9 1a8 8 0 1 0 0 16A8 8 0 0 0 9 1zm.81 12.13c-.02.71-.55 1.15-1.24 1.13-.66-.02-1.17-.49-1.15-1.2.02-.72.56-1.18 1.22-1.16.7.03 1.2.51 1.17 1.23zM11.77 8a5.8 5.8 0 0 1-1.02.91l-.53.37c-.26.2-.42.43-.5.69a4 4 0 0 0-.09.75c0 .05-.03.16-.18.16H7.88c-.16 0-.18-.1-.18-.15.03-.66.12-1.21.4-1.66a5.29 5.29 0 0 1 1.43-1.22c.16-.12.28-.25.38-.39a1.34 1.34 0 0 0 .02-1.71c-.24-.31-.51-.46-1.03-.46-.51 0-.8.26-1.02.6-.21.33-.18.73-.18 1.1H5.75c0-1.38.35-2.25 1.1-2.76.52-.35 1.17-.5 1.93-.5 1 0 1.79.18 2.49.71.64.5.98 1.18.98 2.12 0 .57-.2 1.05-.48 1.44z',
  7.                 'inner_id' : 'related-tags'
  8.             },
  9.             'HOT_NETWORK_QUESTIONS' : {
  10.                 'old_find' : 'div#hot-network-questions',
  11.                 'icon_path' : 'M7.48.01c.87 2.4.44 3.74-.57 4.77-1.06 1.16-2.76 2.02-3.93 3.7C1.4 10.76 1.13 15.72 6.8 17c-2.38-1.28-2.9-5-.32-7.3-.66 2.24.57 3.67 2.1 3.16 1.5-.52 2.5.58 2.46 1.84-.02.86-.33 1.6-1.22 2A6.17 6.17 0 0 0 15 10.56c0-3.14-2.74-3.56-1.36-6.2-1.64.14-2.2 1.24-2.04 3.03.1 1.2-1.11 2-2.02 1.47-.73-.45-.72-1.31-.07-1.96 1.36-1.36 1.9-4.52-2.03-6.88L7.45 0l.03.01z',
  12.                 'inner_id' : 'hot-network-questions'
  13.             },
  14.             'RELATED_QUESTIONS' : {
  15.                 'old_find' : 'div.sidebar-related',
  16.                 'icon_path' : 'M9 1a8 8 0 1 0 0 16A8 8 0 0 0 9 1zm.81 12.13c-.02.71-.55 1.15-1.24 1.13-.66-.02-1.17-.49-1.15-1.2.02-.72.56-1.18 1.22-1.16.7.03 1.2.51 1.17 1.23zM11.77 8a5.8 5.8 0 0 1-1.02.91l-.53.37c-.26.2-.42.43-.5.69a4 4 0 0 0-.09.75c0 .05-.03.16-.18.16H7.88c-.16 0-.18-.1-.18-.15.03-.66.12-1.21.4-1.66a5.29 5.29 0 0 1 1.43-1.22c.16-.12.28-.25.38-.39a1.34 1.34 0 0 0 .02-1.71c-.24-.31-.51-.46-1.03-.46-.51 0-.8.26-1.02.6-.21.33-.18.73-.18 1.1H5.75c0-1.38.35-2.25 1.1-2.76.52-.35 1.17-.5 1.93-.5 1 0 1.79.18 2.49.71.64.5.98 1.18.98 2.12 0 .57-.2 1.05-.48 1.44z',
  17.                 'inner_id' : 'related-questions'
  18.             },
  19.             'FREQUENTLY_ASKED_QUESTIONS' : {
  20.                 'old_find' : 'div.module h4:contains(Frequently Asked)',
  21.                 'icon_path' : 'M11 4l2.29 2.29L10.5 9l-3-3L1 12.5 2.5 14l5-5 3 3 4.21-4.29L17 10V4z',
  22.                 'inner_id' : 'frequently-asked-questions'
  23.             },
  24.             'LINKED_QUESTIONS' : {
  25.                 'old_find' : 'div.sidebar-linked',
  26.                 'icon_path' : 'M2.9 9c0-1.16.94-2.1 2.1-2.1h3V5H5a4 4 0 1 0 0 8h3v-1.9H5A2.1 2.1 0 0 1 2.9 9zM13 5h-3v1.9h3a2.1 2.1 0 1 1 0 4.2h-3V13h3a4 4 0 1 0 0-8zm-7 5h6V8H6v2z',
  27.                 'inner_id' : 'linked-questions'
  28.             },
  29.             'QUESTION_STATS' : {
  30.                 'old_find' : 'div.question-stats',
  31.                 'icon_path' : 'M3 1h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V3c0-1.1.9-2 2-2zm1 8v5h2V9H4zm4-5v10h2V4H8zm4 3v7h2V7h-2z',
  32.                 'inner_id' : 'question-stats'
  33.             },
  34.             'PEOPLE_CHATTING' : {
  35.                 'old_find' : 'div#chat-feature',
  36.                 'icon_path' : 'M4 14l-3 3V3c0-1.1.9-2 2-2h12a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4zm0-8v1h10V6H4zm0-2v1h10V4H4zm0 4v1h10V8H4zm0 2v1h7v-1H4z',
  37.                 'inner_id' : 'people-chatting'
  38.             }
  39.         };
  40.  
  41.         for (var key in widget_array) {
  42.             var row = widget_array[key];
  43.  
  44.             var oldelem = main_content.find(row.old_find);
  45.             if(row.inner_id == "frequently-asked-questions" || row.inner_id == "community-bulletin") {
  46.                 oldelem = oldelem.parent();
  47.             }
  48.  
  49.             var title = row.inner_id == "people-chatting" ? $('a#h-chat-link').parent().html() : row.inner_id.replace(/-/g, ' ').replace(/\b\S/g, function(t) { return t.toUpperCase() });
  50.  
  51.             var newelem = '\
  52.                <div class="s-sidebarwidget" style="margin-bottom:19.500px;">\
  53.                     <div class="s-sidebarwidget--header grid">\
  54.                         <span class="grid--cell mr4"><svg style="fill:#6a737c;" width="18" height="18" viewBox="0 0 18 18"><path d="'+ row.icon_path +'"/></svg></span>\
  55.                         <span id="visualcrumbs-widget-title" class="grid--cell fl1">' + title + '</span>\
  56.                     </div>\
  57.                     <div id="visualcrumbs-'+ row.inner_id +'" class="s-sidebarwidget--content fd-column"></div>\
  58.                </div>\
  59.            ';
  60.  
  61.             oldelem.before(newelem).children('h4, a').remove().parent();
  62.             newelem = main_content.find('div#visualcrumbs-' + row.inner_id);
  63.  
  64.             if(row.inner_id == "related-tags") {
  65.                 newelem.prepend(oldelem.children()).children().wrapAll('<div class="js-watched-tag-list grid gs4 py4 fw-wrap">').each(function() {
  66.                     $(this).toggleClass('dno js-hidden js-tag grid--cell').children().slice(1).remove();
  67.                 });
  68.             } else {
  69.                 newelem.prepend(oldelem.css('margin-bottom', '0px'));
  70.             }
  71.             newelem.find('p.label-key').css('margin-bottom', '0px');
  72.  
  73.             console.log('VisualCrumbs: Converted ' + key);
  74.  
  75.         }
  76.  
  77.      });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement