Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. // Made by Cerulean#7014. For use of adding extra features into the discord client itself
  2. function add_to_discord(elm_name, location, icon, title, from_cache) {
  3. window.button_count = 3;
  4. icon || (icon = 'https://www.evolutioncycles.co.nz/image/cross.png');
  5. title || (title = 'Addons');
  6. from_cache || (from_cache = false);
  7. var spacer = $('<div style="width: 100%; height: 20px;"></div>');
  8.  
  9. var title_element = $('<header>' + title +'</header>');
  10. var butt = $($($("div[class*='scroller-']")[1]).children()[1]).clone();
  11. var fixed_button = butt.find('.channel-name').text(elm_name);
  12. $(butt).find('.channel-name').replaceWith(fixed_button);
  13. $(butt).find('svg').remove();
  14. var a = $(butt).find('a').prepend('<img class="link-button-icon" src="' + icon + '"/>');
  15.  
  16. $(butt).removeClass('selected');
  17. $(butt).attr('data-button', '1');
  18. $(butt).click(function(e) {
  19. e.preventDefault();
  20. handle_click(location);
  21. });
  22. console.log(window.button_count);
  23. if (title != 'Addons') {
  24. $($("div[class*='scroller-']")[1]).insert_at(window.button_count, $(title_element));
  25. window.button_count = window.button_count + 1;
  26. };
  27. $($("div[class*='scroller-']")[1]).insert_at(window.button_count, $(butt));
  28. window.button_count = window.button_count + 1;
  29. if (!from_cache) {
  30. window.buttons.push({name: elm_name, location: location, icon: icon, title: title});
  31. }
  32.  
  33. };
  34.  
  35. function handle_click(location) {
  36. //$($("div[class*='channels-']").siblings()[0]).html('<iframe src="' + location + '" style="height:100%"></iframe>');
  37. var error_page = '<div style="display:flex;align-items:center;justify-content:center;height:100%;width:100%;flex-flow:column;"><h1 style="color:#fff;">There was an error!</h1><p style="color:#ccc;">We couldnt grab that page due to an error. Please check the console log!</p></div>'
  38. $.ajax({url: location}).done(function (html) {$($("div[class*='channels-']").siblings()[0]).html(html)}).fail(function () {$($("div[class*='channels-']").siblings()[0]).html($(error_page))});
  39. $('.channel.selected').removeClass('selected');
  40. $(this).addClass('selected');
  41. };
  42. window.buttons = [];
  43. function hook_tag () {
  44. $('a').click(function () {
  45. var a = $(this);
  46. setTimeout(function () {
  47. if ($(a).attr('href') == '/activity') {
  48. window.buttons.forEach(function (item) {add_to_discord(item.name, item.location, item.icon, item.title, from_cache=true);})
  49.  
  50. }
  51. },150);
  52. });
  53. }
  54.  
  55. jQuery.fn.insert_at = function(index, element) {
  56. var lastIndex = this.children().size();
  57. if (index < 0) {
  58. index = Math.max(0, lastIndex + 1 + index);
  59. }
  60. this.append(element);
  61. if (index < lastIndex) {
  62. this.children().eq(index).before(this.children().last());
  63. }
  64. return this;
  65. };
  66. hook_tag();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement