Seven Yu @ 02/28/2009 (8:42 am)

支持手动/自动更新 twitter timeline 的 GM 脚本

Tags: , ::

最近跟 twitter 干上了, 在 sfufoetPaveo 的怂恿下都快成 GM 狂人了 :x

昨天拖着我的麦粒肿又折腾到凌晨, 出炉了下面的 GM 脚本… [安装脚本]

Twitter timeline updater

  • 支持手动更新和自动更新
  • 受 twitter api 访问频率限制(每小时访问至多100次), 自动更新时间设为45秒
  • 更新内容以淡黄色为背景, 鼠标滑过恢复正常背景色
  • 更新内容时间显示客户端时区时间
  • v1.2.1 标题上显示未读计数
  • v1.2.1 记忆自动更新状态
  • v1.3.1 自动替换网址和 reply 链接
  • v1.3.2 增加 Make all read 按钮
  • v1.3.2 Refresh 和 Make all read 链接以图标表示
  • v1.3.2 修复了重复更新的 bug
  • v1.3.5 格式化日期

Seven Yu @ 02/26/2009 (9:16 pm)

最近写的两个 twitter GM 脚本

Emoji!!!

脚本安装地址: http://userscripts.org/scripts/show/42569

Display/Insert iPhone’s Emoji icon on webpages. 显示/插入 iPhone 的 emoji 表情。

Twitter friends name helper

脚本安装地址: http://userscripts.org/scripts/show/43117

Tip:The helper is available when the input background color turns into light blue as the image.

输入 @ 或 用户名 可以自动完成

或者点击好友列表头像上的图标直接 reply 或 send direct message.

Seven Yu @ 02/14/2009 (2:43 pm)

php 条形码类

Tags: , ::

演示: http://labs.phpz.org/barcode/

BarCode 类:

PLAIN TEXT >> PHP:
  1. <?php
  2. /*
  3. * Bar Code
  4. * author: Seven Yu
  5. * E-mail: dofyyu@gmail.com
  6. */
  7. class BarCode{
  8. private $data;
  9. private $order;
  10. private $code;
  11. private $mode;
  12.  
  13. private $startX, $endX, $startY, $offsetX, $offsetY;
  14. private $fontsize, $txtbgX0;
  15. private $txtbgX1, $txtbgX2, $txtbgX3, $txtbgX4, $txtbgY1, $txtbgY2;
  16.  
  17. private $im;
  18.  
  19. private $b, $s;
  20.  
  21. function __construct($code = null, $mode = 'html'){
  22.    
  23.     $this->startX = 20;
  24.     $this->startY = 10;
  25.     $this->offsetX = 2;
  26.     $this->offsetY = 80;
  27.    
  28.     $this->fontsize = 5;
  29.    
  30.     $this->txtbgX0 = $this->startX;
  31.     $this->txtbgX1 = $this->startX+$this->offsetX*3;
  32.     $this->txtbgX2 = $this->txtbgX1+$this->offsetX*42;
  33.     $this->txtbgX3 = $this->txtbgX2+$this->offsetX*5;
  34.     $this->txtbgX4 = $this->txtbgX3+$this->offsetX*42;
  35.     $this->txtbgY2 = $this->startY+$this->offsetY;
  36.     $this->txtbgY1 = $this->txtbgY2-15;
  37.    
  38.     $this->loadData();
  39.     $this->setMode($mode);
  40.     if(!is_null($code))
  41.         $this->setCode($code);
  42. }
  43.  
  44. function setMode($mode){
  45.     $this->mode = strtolower($mode) == 'img'? 'img': 'html';
  46. }
  47.  
  48. function setCode($code){
  49.     $reg = "/^\d{13}$/";
  50.     if(preg_match($reg, $code)){
  51.         $this->code = $code;
  52.     }else{
  53.         $this->code = null;
  54.         $this->ERROR('Need a 13 bit Number.');
  55.     }
  56. }
  57.  
  58. function makeImg($width, $height){
  59.     header('Content-type: image/png');
  60.     header('Content-Disposition: attachment; filename="BarCode.png"');
  61.     $this->im = imagecreate($width, $height);
  62.     $this->s = imagecolorallocate($this->im, 255, 255, 255);
  63.     $this->b = imagecolorallocate($this->im, 0, 0, 0);
  64.     $this->t = imagecolorallocate($this->im, 100, 100, 100);
  65. }
  66.  
  67. function endImg(){
  68.     imagepng($this->im);
  69. }
  70.  
  71. function makeRect($col){
  72.     $this->endX = $this->startX + $this->offsetX;
  73.     $col = $col == 1? $this->b: $this->s;
  74.    
  75.     $this->myRect($this->startX, $this->startY, $this->endX, $this->startY+$this->offsetY, $col);
  76.     $this->startX = $this->endX;
  77. }
  78.  
  79. function myRect($x1, $y1, $x2, $y2, $col){
  80.     imagefilledrectangle($this->im, $x1, $y1, $x2-1, $y2-1, $col);
  81. }
  82.  
  83. function myText($x1, $y1, $str){
  84.     imagestring($this->im, $this->fontsize, $x1, $y1, $str, $this->b);
  85. }
  86.  
  87. function ERROR($msg){
  88.     if($this->mode == 'img'){
  89.         $this->makeImg(strlen($msg)*10, 30);
  90.         $this->myText(5, 5, $msg);
  91.         $this->endImg();
  92.     }else{
  93.         echo $msg;
  94.     }
  95. }
  96.  
  97. function makeBarCode(){
  98.     if(is_null($this->code)){
  99.         $this->ERROR('Need Code');
  100.     }else{
  101.         // get array
  102.         $final = array();
  103.         $rule = $this->order[$this->code[0]];
  104.         $final = array_merge($final, $this->data['bgn']);
  105.         for($i=1; $i<7; $i++){
  106.             $final = array_merge($final, $this->data[$this->code[$i]][$rule[$i-1]]);
  107.         }
  108.         $final = array_merge($final, $this->data['mid']);
  109.         for(; $i<13; $i++){
  110.             $final = array_merge($final, $this->data[$this->code[$i]]['c']);
  111.         }
  112.         $final = array_merge($final, $this->data['end']);
  113.        
  114.         if($this->mode == 'img'){
  115.             // make img
  116.             $width  = $this->startX*2 + $this->offsetX*95;
  117.             $height = $this->startY*2 + $this->offsetY;
  118.             $this->makeImg($width, $height);
  119.             // draw bar
  120.             for($i=0; $i<95; $i++){
  121.                 $this->makeRect($final[$i]);
  122.             }
  123.             // draw text background
  124.             $this->myRect($this->txtbgX1, $this->txtbgY1, $this->txtbgX2, $this->txtbgY2, $this->s);
  125.             $this->myRect($this->txtbgX3, $this->txtbgY1, $this->txtbgX4, $this->txtbgY2, $this->s);
  126.             // write text
  127.             for($i=0; $i<13; $i++){
  128.                 if($i == 0){
  129.                     $offsetX = -2;
  130.                 }else if($i <7){
  131.                     $offsetX = $this->offsetX*3;
  132.                 }else{
  133.                     $offsetX = $this->offsetX*8;
  134.                 }
  135.                 $this->myText($offsetX+$this->txtbgX0+$this->offsetX*7*$i-$this->offsetX*5, $this->txtbgY1, $this->code[$i]);
  136.             }
  137.             $this->myText($this->startX+3, $this->txtbgY1, '>');
  138.            
  139.             $this->endImg();
  140.         }else{
  141.             // html mode
  142.             echo '<style type="text/css">
  143. .line_0, .line_1{
  144.     float: left;
  145.     width: ' . $this->offsetX . 'px;
  146.     height: 100px;
  147. }
  148. .line_0{
  149.     background: #FFFFFF;
  150. }
  151. .line_1{
  152.     background: #000000;
  153. }
  154. </style>';
  155.             for($i=0; $i<95; $i++){
  156.                 echo "\n" . '<div class="line_' . $final[$i] . '"></div>';
  157.             }
  158.         }
  159.     }
  160.  
  161. }
  162.  
  163. function loadData(){
  164.     $this->data = array();
  165.     $this->order = array();
  166.    
  167.     $this->data['bgn']  = array(1,0,1);
  168.     $this->data['mid']  = array(0,1,0,1,0);
  169.     $this->data['end']  = array(1,0,1);
  170.     $this->data[0]['a'] = array(0,0,0,1,1,0,1);
  171.     $this->data[0]['b'] = array(0,1,0,0,1,1,1);
  172.     $this->data[0]['c'] = array(1,1,1,0,0,1,0);
  173.     $this->data[1]['a'] = array(0,0,1,1,0,0,1);
  174.     $this->data[1]['b'] = array(0,1,1,0,0,1,1);
  175.     $this->data[1]['c'] = array(1,1,0,0,1,1,0);
  176.     $this->data[2]['a'] = array(0,0,1,0,0,1,1);
  177.     $this->data[2]['b'] = array(0,0,1,1,0,1,1);
  178.     $this->data[2]['c'] = array(1,1,0,1,1,0,0);
  179.     $this->data[3]['a'] = array(0,1,1,1,1,0,1);
  180.     $this->data[3]['b'] = array(0,1,0,0,0,0,1);
  181.     $this->data[3]['c'] = array(1,0,0,0,0,1,0);
  182.     $this->data[4]['a'] = array(0,1,0,0,0,1,1);
  183.     $this->data[4]['b'] = array(0,0,1,1,1,0,1);
  184.     $this->data[4]['c'] = array(1,0,1,1,1,0,0);
  185.     $this->data[5]['a'] = array(0,1,1,0,0,0,1);
  186.     $this->data[5]['b'] = array(0,1,1,1,0,0,1);
  187.     $this->data[5]['c'] = array(1,0,0,1,1,1,0);
  188.     $this->data[6]['a'] = array(0,1,0,1,1,1,1);
  189.     $this->data[6]['b'] = array(0,0,0,0,1,0,1);
  190.     $this->data[6]['c'] = array(1,0,1,0,0,0,0);
  191.     $this->data[7]['a'] = array(0,1,1,1,0,1,1);
  192.     $this->data[7]['b'] = array(0,0,1,0,0,0,1);
  193.     $this->data[7]['c'] = array(1,0,0,0,1,0,0);
  194.     $this->data[8]['a'] = array(0,1,1,0,1,1,1);
  195.     $this->data[8]['b'] = array(0,0,0,1,0,0,1);
  196.     $this->data[8]['c'] = array(1,0,0,1,0,0,0);
  197.     $this->data[9]['a'] = array(0,0,0,1,0,1,1);
  198.     $this->data[9]['b'] = array(0,0,1,0,1,1,1);
  199.     $this->data[9]['c'] = array(1,1,1,0,1,0,0);
  200.    
  201.     $this->order[0] = array('a','a','a','a','a','a');
  202.     $this->order[1] = array('a','a','b','a','b','b');
  203.     $this->order[2] = array('a','a','b','b','a','b');
  204.     $this->order[3] = array('a','a','b','b','b','a');
  205.     $this->order[4] = array('a','b','a','a','b','b');
  206.     $this->order[5] = array('a','b','b','a','a','b');
  207.     $this->order[6] = array('a','b','b','b','a','a');
  208.     $this->order[7] = array('a','b','a','b','a','b');
  209.     $this->order[8] = array('a','b','a','b','b','a');
  210.     $this->order[9] = array('a','b','b','a','b','a');
  211. }
  212. // end class
  213. }
  214. ?>

应用:

PLAIN TEXT >> PHP:
  1. <?php
  2. require('BarCode.php');
  3.  
  4. $code = $_GET['code'];
  5. $mode = strtolower(trim($_GET['mode']));
  6.  
  7. $mode = $mode == 'html'? 'html': 'img';
  8.  
  9. $bc = new BarCode($code, $mode);
  10. $bc->makeBarCode();
  11. ?>