PaintMyHabr

Paint editors posts in yellow, futile posts in pink, add "PAID" stamp to companies posts on habrahabr.ru/geektimes.ru

  1. // ==UserScript==
  2. // @name PaintMyHabr
  3. // @description Paint editors posts in yellow, futile posts in pink, add "PAID" stamp to companies posts on habrahabr.ru/geektimes.ru
  4. // @namespace riot26.ru
  5. // @author riot26
  6. // @license WTFPL (http://www.wtfpl.net/txt/copying)
  7. // @include http://geektimes.ru/*
  8. // @include https://geektimes.ru/*
  9. // @include http://habrahabr.ru/*
  10. // @include https://habrahabr.ru/*
  11. // @exclude http://geektimes.ru/post/*
  12. // @exclude https://geektimes.ru/post/*
  13. // @exclude http://habrahabr.ru/post/*
  14. // @exclude https://habrahabr.ru/post/*
  15. // @version 2.01
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. var css = document.createElement('style');
  20. css.type = 'text/css';
  21. css.media = 'screen';
  22. css.innerHTML = '.post {padding:10px !important; position:relative !important;}'
  23. +'.yellow {background-color:#FFFFE5 !important;}'
  24. +'.pink {background-color:#FFF3F9 !important; background-image:url(https://i.imgur.com/74u5ZhC.jpg);}'
  25. +'.paid_stamp {position:absolute; width:130px; height:75px; background:url(https://i.imgur.com/xcyAC4P.png); top:2px; right:2px;}'
  26. +'.buttons {padding:20px 0 20px 0 !important;}'
  27. +'.fonts-loaded .post__flow, .fonts-loaded .post_title, .fonts-loaded .post__title, .fonts-loaded .post__title_link { font-family:\'Fira Sans\',\'Helvetica Neue\',Helvetica,sans-serif !important; }'
  28. +'.post__flow, .post__title, .post__title_link {font-size:22px !important; font-family:Arial,\'Helvetica Neue\',Helvetica,sans-serif !important; }';
  29. document.getElementsByTagName('head')[0].appendChild(css);
  30.  
  31. var posts = document.getElementsByClassName('post');
  32. for (var i = 0; i < posts.length; i++) {
  33. if (isEditors(posts[i])) {
  34. posts[i].className += posts[i].className ? ' yellow' : 'yellow';
  35. }
  36. if (isPaid(posts[i])) {
  37. addPaidStamp(posts[i]);
  38. }
  39. if (isFutile(posts[i])) {
  40. posts[i].className += posts[i].className ? ' pink' : 'pink';
  41. }
  42. }
  43.  
  44. function isEditors(post) {
  45. var editors = ['SLY_G', 'alizar', 'marks', 'ivansychev', 'ragequit'];
  46. if (post.querySelector(".post-author__link")) {
  47. return containsAny(post.querySelector(".post-author__link").getAttribute('href'), editors);
  48. }
  49. return false;
  50. }
  51.  
  52. function isFutile(post) {
  53. var futile_flows = ['design', 'marketing', 'management', 'misc'];
  54. if (post.querySelector(".post__flow")) {
  55. return containsAny(post.querySelector(".post__flow").getAttribute('href'), futile_flows);
  56. }
  57. return false;
  58. }
  59.  
  60. function isPaid(post) {
  61. if (post.querySelector(".hubs")) {
  62. return post.querySelector(".hubs").outerHTML.indexOf('Блог компании') != -1;
  63. } else {
  64. return post.querySelector(".megapost-cover__inner");
  65. }
  66. }
  67.  
  68. function addPaidStamp(post) {
  69. var paid_stamp_el = document.createElement('div');
  70. paid_stamp_el.className = 'paid_stamp';
  71. post.appendChild(paid_stamp_el);
  72. }
  73.  
  74. function containsAny(str, substrings) {
  75. for (var i = 0; i != substrings.length; i++) {
  76. var substring = substrings[i];
  77. if (str.indexOf(substring) != -1) {
  78. return true;
  79. }
  80. }
  81. return false;
  82. }