4chan Text Functions

Allows usage of [spoiler]Spoilers[/spoiler] and >greentext inside of picarto chats. See http://imgur.com/a/b8cmO for examples

目前為 2015-08-28 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 4chan Text Functions
  3. // @namespace Wolvan_PicartoTV_4chan_Chat_Functions
  4. // @version 1.0
  5. // @description Allows usage of [spoiler]Spoilers[/spoiler] and >greentext inside of picarto chats. See http://imgur.com/a/b8cmO for examples
  6. // @author Wolvan
  7. // @match *://*.picarto.tv/live/channel.php?*watch=*
  8. // @match *://*.picarto.tv/live/multistream.php?*watch=*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. // Get Picarto's jQuery instance, no need to polute it with our own
  13. var $ = window.jQuery;
  14.  
  15. // A function to inject CSS into the site
  16. function addCSS(css) {
  17. var head, style;
  18. head = document.getElementsByTagName('head')[0];
  19. if (!head) { return; }
  20. style = document.createElement('style');
  21. style.type = 'text/css';
  22. style.innerHTML = css;
  23. head.appendChild(style);
  24. }
  25.  
  26. // On appending a new message to the messages container we replace the new message's control codes ([spoiler]/[/spoiler]) with properly css-formatted <s> tags
  27. // We also bind the mouseover and mouseout events to hide the spoilers again when you remove the mousecursor
  28. $("#msgs").on("append", function(){
  29. var incoming = $(".messageli:last").html();
  30. if (typeof(incoming) !== "undefined") {
  31. var processed = incoming.replace(/\[spoiler\]/gi, "<s>").replace(/\[\/spoiler\]/gi, "</s>");
  32. var countS = (processed.match(/<s>/g) || []).length;
  33. var countSE = (processed.match(/<\/s>/g) || []).length;
  34. var countDiff = countS - countSE;
  35. if (countDiff > 0) {
  36. for(i = 0; i <= countDiff; i++) {
  37. processed = processed + "</s>";
  38. }
  39. }
  40. $(".messageli:last").html(processed).find("s").mouseover(function() {
  41. $(this).css("color", "white");
  42. }).mouseout(function() {
  43. $(this).css("color", "black");
  44. });
  45. }
  46. });
  47.  
  48. // Add the CSS to have the spoilers be black boxes without a strikethrough
  49. addCSS(' \
  50. s { \
  51. background-color: black; \
  52. color: black; \
  53. text-decoration: none; \
  54. }\
  55. ');
  56.  
  57. // On appending a new message to the message container we check if the first char of the message is > and turn the message green
  58. $("#msgs").on("append", function(){
  59. var msg = $(".messageli:last").find(".msgContent");
  60. if (msg.text().startsWith(">")) {
  61. msg.css("color", "#8ba446");
  62. }
  63. });