Advertisement
Gotolei

Untitled

Apr 28th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           TPP Touchscreen
  3. // @version        1.0
  4. // @namespace      
  5. // @author         lostcoaster
  6. // @description    Adds a clickable area over the touchscreen part of the stream for easy input. http://redd.it/247cvf
  7. // @include        /^https?://(www|beta)\.twitch\.tv\/twitchplayspokemon(/(chat.*)?)?$/
  8. // @run-at         document-end
  9. // ==/UserScript==
  10.  
  11. $('#player').append('<div class="touch_overlay" style="border:red solid;"></div>');
  12. var touch_pad={
  13.     factor : 1,
  14.     // reflect mouse event to coordinate output.
  15.     coords : function(event){
  16.         return Math.floor((event.pageX-$(event.target).offset().left)/this.factor)
  17.                 +','+
  18.                 Math.floor((event.pageY-$(event.target).offset().top)/this.factor);
  19.     },
  20.     // adjust position of the box, parameters are relative position of top-left corner of the box within stream screen
  21.     // 0 <= rx,ry <= 1
  22.     position : function(rx, ry){
  23.         // base on the facts :
  24.         // 1. image always fills vertically, but not horizontally ;
  25.         // 2. the bar is 30px tall (constant), or 31px, whatever;
  26.         // 3. source is 16:9;
  27.         // 4. the REAL touch screen has a 256*192 resolution;
  28.         var base = $('#player');
  29.         var base_offset = base.offset();
  30.         var real_height = base.height()-30.5;
  31.         this.factor = real_height/440;  // rough estimation
  32.         var real_width = real_height/9*16;
  33.         var left_margin = (base.width()-real_width)/2;
  34.         $('.touch_overlay').offset({
  35.             top: base_offset.top + ry*real_height,
  36.             left: base_offset.left + left_margin + rx*real_width
  37.         }).height(192*this.factor).width(256*this.factor);
  38.     },
  39.     aim: function(){
  40.         this.position(0.36,0.548); // rough estimation No.2
  41.     }
  42.  
  43. };
  44. $('.touch_overlay').mouseup(function(event){
  45.     $('textarea').val(touch_pad.coords(event));
  46. });
  47. // add the reaiming into settings menu. idea stolen from the chat-filter : http://redd.it/1y8ukl
  48. $('.chat-settings').append('<div class="chat-menu-content"><button onclick="touch_pad.aim()">Reposition Touchpad</button></div>');
  49. touch_pad.aim();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement