扑克类互动游戏:
年会活动:数钱
天道酬勤,知足常乐
示例:
http://24.igd.cc/workerman/page?caihaibin=ok
外部使用demo
http://24.igd.cc/workerman_remote/page?caihaibin=ok
http://gxu.igd.cn/workerman_remote/page?caihaibin=ok
(端口只有一个, 多个项目使用同一个workerman,通过特殊机制,实现将workerman请求转发到yii,并共享两边的sessiono数据,支持wss)
需要明确一个关键点,workerman本身是一个独立的运行容器,类似 apache+php的概念,独立运行.
因为 workerman 是一个独立的脚本容器,所以这类代码
lib ( ‘workerman/Gateway.php’ );
\GatewayClient\Gateway::joinGroup ( State ( ‘client_id’ ), WebSocketTools::KEY_PRE . ‘test’ );
其实比较像调用workerman的接口,实现相关功能.需要理解这块,所以两者有一定的时间差,这块初试化时,必须认login推送返回的消息为准,做为完全建立两者通讯的标志.如果没有,页面应当进行刷新,再次进行连接.有时websocket open是成功的,但是login消息也会没有推送回来,表示之前的网络通讯出了问题.当做不成功.
workerman 游戏的两种模式
第一种:
一种频率不高的,几秒甚至十几秒点一次的,如猜拳,24点小游戏.直接使用post调用yii动作实现游戏逻辑.
第二种:
频率非常高的,类似数钱,一秒会有数次请求的,全部走workerman session,不经过yii session 和数据库. 前台屏幕数据显示,可通过gatewayclient获取workerman所有的会话数据,再根据数据进行排名显示. 当比赛结束时,再将数据插入数据库.
//===============发送workerman 内部参数,用于直接调用workerman动作===============
// 自定义一个key 和 value ,一秒内多次推送也不影响性能
ws.send(JSON.stringify({model:’__workerman’,action:’set_value’,value_key:’score’,value_value:Math.random(0)}));
//===============发送workerman 内部参数,用于直接调用workerman动作
//gateway 获取session数据,不同项目,分组前缀必须不同,防止冲突
Gateway::getAllClientSessions ( WebSocketTools::KEY_PRE . ‘test’ )
只针对模块形式代码进行yii1到yii2的转化,config中需要手动进行补充配置.
<?PHP
header ( 'Content-Type: text/html; charset=utf-8' );
include 'FileTools.php';
include 'lib.php';
// 需要转换的模块
$path = 'D:/PHPnow-1.5.6/htdocs/igddata/yii2sys/app/modules/member/';
// $path = 'D:/PHPnow-1.5.6/htdocs/igddata/yii2sys/app/';
// 根路径,用于识别命名空间
$root_path = 'D:/PHPnow-1.5.6/htdocs/igddata/yii2sys/';
$root_path = preg_replace ( '/\//', '\\', $root_path );
$preg_file = array ();
// Yii::$app->user->setState('_id',$identity->_id); 修改 成 Yii::$app->session->set ( '_id', $identity->getId () );
// ar getList findAll 需要针对性处理.
// CHTML
// <?
$preg_contents = array (
'/Yii\:\:app\s*?\(\)/' => 'Yii::$app',
// $app->params->membermodules => 变成数组 ['membermodules']
'/Yii\:\:\$app\-\>params\-\>(\w+)/' => 'Yii::$app->params[\'\\1\']',
// 直接调用\Yii跳过use
'/(?<!\\\\)Yii/' => '\Yii',
// CHTML 全部调整成 \yii\helpers\Html
'/(?<!\\\\)CHTML/ims' => '\yii\helpers\Html',
// 所有短标签自动补充成<?php
'/\<\?(\s)/' => '<?php\\1',
// post请求判断切换成yii2形式判断
'/isPostRequest/' => 'isPost',
'/getIsPostRequest\s*\(\s*\)/' => 'isPost',
// user->setState 在新版本中已经被取消
'/user\-\>setState/' => 'session\-\>set',
// 统一当前登录用户获取用户id
'/\>\_id/' => '>getId ()',
// 所有原参数获取,调整为默认获取
'/getParam\s*\(\s*?([\'\"\w]+)[^\)]*?\)/ims' => '$_REQUEST[\\1]',
// '/render\s*\(/' => 'renderPartial(',
// 渲染页面动作需要进行返回
'/\n(\s*)\$this\-\>render/' => '
\\1return $this->render',
// 统一当前登录用户获取用户id
'/user\-\>\_id/' => 'user->getId()',
// getAttributes()不能带false参数, 不然会导致出错
'/getAttributes\s*\(\s*false\s*\)/' => 'getAttributes()',
// ;;去除无效代码,但是for(;;)需要绕过
'/(?<!\()\;\s*\;/' => ';',
// 补充表前缀
'/\{\{(?=\w)/' => '{{%',
'/findByPk/i' => 'findOne',
// 所有数组修改成新形式
'/(?<!\w)array\s*\(([^\(\)]*?)\)/ms' => '[\\1]',
'/jquery\-easyui\-1\.2\.5/ims' => 'jquery-easyui-1.3.1',
'/public\s*function\s*tableName/ims' => 'public static function tableName',
'/getAction\s*\(\)/' => 'action',
// load为默认函数,不可用该函数名,全部调整为loadModel
'/([\s\>])load\s*\(/' => '\\1loadModel(',
// 修改http异常,并直接引用
'/CHttpException/' => '\yii\web\HttpException',
// 修改ar继承类
'/extends CActiveRecord/' => 'extends \yii\db\ActiveRecord',
// 修改注释,用于引入框架时,实现代码提示
'/CActiveRecord/' => 'ActiveRecord',
'/action\-\>getId\s*\(\)/' => 'action->id',
'/getController\s*\(\)/' => 'controller',
'/controller\-\>getId\s*\(\)/' => 'controller->id',
'/getModule\s*\(\)/' => 'module',
'/module\-\>getId\s*\(\)/' => 'module->id',
// array 引用
'/require\_once\s*\(\s*[\'\"]array\.php[\'\"]\s*\)\;/ims' => 'lib(\'array.php\');',
'/require\_once\s*\(\s*[\'\"]array2\.php[\'\"]\s*\)\;/ims' => 'lib(\'array2.php\');',
// 去除WebControls引用
'/require\_once\s*\(\s*[\'\"]WebControls\.php[\'\"]\s*\)\;/' => '',
// 直接调用WebControls
'/new WebControls/' => 'new \ext\WebControls',
// 去除MysqlTools引用
'/require\_once\s*\([\'\"]MysqlTools\.php[\'\"]\)\;/' => '',
'/lib\s*\(\s*[\'\"]MysqlTools\.php[\'\"]\s*\)\;/' => '',
// 直接调用MysqlTools
'/(?<!\\\\)MysqlTools/' => '\ext\MysqlTools',
// GCheckData直接转化
'/(?<!\\\\)GCheckData/' => '\ext\GCheckData',
// 替换控制器集成类
'/extends\s*CController/' => 'extends \yii\web\Controller',
// beforeAction只能为公开函数
'/protected\s*function\s*beforeAction/ims' => 'public function beforeAction',
// 判断到有beforeAction的,需要进行父函数调用,否则会导致过滤器失效
'/beforeAction/' => function ($path, $content) {
// 有使用before,但是没有进行父函数调用,需要补充父类beforeAction调用
if (! preg_match ( '/parent\:\:beforeAction/', $content )) {
$content = preg_replace ( '/beforeAction[^\{]+?\{/ims', 'beforeAction($action) {
// 需要调用父函数,否则不会触发过滤器
if (!parent::beforeAction ( $action )) {
return false;
}', $content );
}
return $content;
},
// 整个替换module.php内容,不然配置文件需要手动修改.
'/CWebModule/' => function ($path, $content) {
$namespace = getNamespaceByPath ( $path );
$content = <<<EOF
<?php
namespace {$namespace};
class Module extends \yii\base\Module {
public function init() {
parent::init ();
}
}
EOF;
return $content;
},
// ar特殊处理,补充命名空间
// 需要先进行命名空间的添加,用于控制器,页面添加对象时,直接识别命名空间,并添加
'/\\\\yii\\\\db\\\\ActiveRecord/' => function ($path, $content) {
$namespace = getNamespaceByPath ( $path );
// \s和(?!)正向零宽断言会导致误判,需要后面补充一个标志
if (! preg_match ( '/^\<\?php\s*namespace/is', $content )) {
$content = preg_replace ( '/^\<\?php\s*/ims', "<?php\nnamespace {$namespace};\n", $content );
}
// ArticleX 的model有特殊实现,不进行替换.
if (! preg_match ( '/ArticleX/', $path ) && preg_match ( '/function\s*model\s*\(/ims', $content )) {
$content = preg_replace ( '/function\s*model\s*\([^\}]+?\}/ims', 'function model($className = __CLASS__) {
return new self ();
}', $content );
}
if (preg_match ( '/function\s*getList\s*\(\s*\$criteria\s*\=\s*null/ims', $content )) {
$content = preg_replace ( '/function\s*getList\s*\(\s*\$criteria\s*\=\s*null\s*/ims', 'function getList($afmodel = null', $content );
$content = preg_replace ( '/(function\s*getList\s*\(\s*\$afmodel\s*\=\s*null\s*[^\;]+?)\$this\-\>findAll\s*\(\s*\$criteria\s*\)\s*\;/ims', '\\1$afmodel->all();', $content );
}
if (preg_match ( '/function\s*getCount\s*\(\s*\$criteria\s*\=\s*null/ims', $content )) {
$content = preg_replace ( '/function\s*getCount\s*\(\s*\$criteria\s*\=\s*null\s*/ims', 'function getCount($afmodel = null', $content );
$content = preg_replace ( '/(function\s*getCount\s*\(\s*\$afmodel\s*\=\s*null\s*[^\;]+?)\$this\-\>count\s*\(\s*\$criteria\s*\)\s*\;/ims', '\\1$afmodel->count();', $content );
}
return $content;
},
// 控制器特殊处理,补充命名空间,修改过滤器
'/\\\\yii\\\\web\\\\Controller/' => function ($path, $content) {
$namespace = getNamespaceByPath ( $path );
$models_namespace = getNamespaceByPath ( dirname ( $path ) ) . '\\models';
// 修改过滤器
// 其它特殊模块,照样修改
if (preg_match ( '/public\s*function\s*filters\(\s*\)\s*\{[^}]+?\}/ims', $content )) {
$string = <<<EOF
public function behaviors() {
return [
'access' => [
'class' => \\ext\\RbacFilter::className ()
]
];
}
EOF;
$content = preg_replace ( '/public\s*function\s*filters\(\s*\)\s*\{[^}]+?\}/ims', $string, $content );
}
// 先获取ar列表,并添加到use中,再添加命名空间
// 获取所有ar,并标记到use中和页面中
$models = getModelsByControllerPath ( $path );
$use_models = array ();
foreach ( $models as $model ) {
$model_ns = $models_namespace . '\\' . $model;
// 判断是否有该类同时判断是否已添加命名空间
if (preg_match ( "/\W{$model}\W/ms", $content ) && ! stristr ( $content, $model_ns )) {
$content = preg_replace ( '/^\<\?php\s*/ims', "<?php\nuse \\{$model_ns};\n", $content );
$use_models [] = $model;
}
}
// 控制器补充命名空间使用
// \s和(?!)正向零宽断言会导致误判,需要后面补充一个标志
// 命名空间前面不能直接加反斜杠,use 前可以
if (! preg_match ( '/^\<\?php\s*namespace/ims', $content )) {
$content = preg_replace ( '/^\<\?php\s*/ims', "<?php\nnamespace {$namespace};\n", $content );
}
// 页面补充命名空间使用
$views = getViewsByControllerPath ( $path );
foreach ( $views as $view ) {
$page_content = file_get_contents ( $view );
// 去除头部和尾部空白部分
$page_content = trim ( $page_content );
// 如果没有php头,就补充php头
if (preg_match ( '/^(?!\<\?php\s*)/i', $page_content )) {
$page_content = preg_replace ( '/^(?!\<\?php\s*)/i', '<?php
?>', $page_content );
}
$use_models = array ();
foreach ( $models as $model ) {
$model_ns = $models_namespace . '\\' . $model;
// 判断是否有该类同时判断是否已添加命名空间
if (preg_match ( "/\W{$model}\W/ms", $page_content ) && ! stristr ( $page_content, $model_ns )) {
$page_content = preg_replace ( '/^\<\?php\s*/is', "<?php\nuse \\{$model_ns};\n", $page_content );
}
}
file_put_contents ( $view, $page_content );
}
return $content;
},
// $criteria =new CDbCriteria 及分页逻辑实现自动转化
'/\$criteria\s*\=\s*new\s*CDbCriteria.+?(\$this|\$model|\w+|\w+\:\:model\s*\(\s*\))\-\>(findAll|find|getList)\s*\([^\;]*?\)\;/ims' => function ($path, $content, $preg) {
while ( preg_match ( $preg, $content, $matchs ) ) {
$subcontent = $matchs [0];
$object = $matchs [1];
// 如果是xxx::model()和$this ,需要对(:,(,),$)补充斜杠,进行转义处理,用于正则表达式
if (preg_match ( '/([\:\(\)\$])/', $object )) {
$preg_object = preg_replace ( '/([\:\(\)\$])/', '\\\\\\1', $object );
}
// 调试识别结果
// gddebug ( $preg_object, $object, $subcontent, $matchs );
// exit ();
// 原CDbCriteria编程ActiveQuery形式,直接通过find返回该对象,取代.
$subcontent = preg_replace ( '/\$criteria\s*\=\s*new\s*CDbCriteria\s*(\(\s*\))?\;/ims', "\$afmodel=(\$afmodel?\$afmodel:{$object}->find());", $subcontent );
// CDbCriteria condition 转化,全部通过andWhere代替,重叠部分,会自动补充and处理
$subcontent = preg_replace ( '/\$criteria\s*\-\>condition\s*\.?\s*\=\s*([^\;]+?)\;/ims', "\$afmodel->andWhere(\\1);", $subcontent );
// CDbCriteria addCondition 转化,全部通过andWhere代替,重叠部分,会自动补充and处理
$subcontent = preg_replace ( '/\$criteria\s*\-\>addCondition\s*\(([^\;]+?)\)\;/ims', "\$afmodel->andWhere(\\1);", $subcontent );
// CDbCriteria order 转化
$subcontent = preg_replace ( '/\$criteria\s*\-\>order\s*\.?\s*\=\s*([^\;]+?)\;/ims', "\$afmodel->orderBy(\\1);", $subcontent );
// CDbCriteria select 转化
$subcontent = preg_replace ( '/\$criteria\s*\-\>select\s*\.?\s*\=\s*([^\;]+?)\;/ims', "\$afmodel->select(\\1);", $subcontent );
// ActiveRecord count 转化
$subcontent = preg_replace ( '/' . $preg_object . '?\s*\-\>count\s*\([^\;]*?\)\;/ims', "\$afmodel->count();", $subcontent );
// 如果出现特殊自定函数,修改传入参数
$subcontent = preg_replace ( '/\-\>getCount\s*\(\s*\$criteria\s*\)/', '->getCount($afmodel)', $subcontent );
// CPagination分页对象转化
$subcontent = preg_replace ( '/new\s*CPagination\s*\(([^\)]+?)\)/ims', 'new \yii\data\Pagination ( [
"totalCount" => \\1
] )', $subcontent );
// 分页大小转化
$subcontent = preg_replace ( '/\$pages\s*\-\>\s*pageSize\s*\=([^\;]+)\;/ims', "\$pages->setPageSize ( \\1 );", $subcontent );
// $pages->applyLimit($criteria) 没用,替换成page变量设置及分页变量带入ActiveQuery处理
$subcontent = preg_replace ( '/\$pages\s*\-\>\s*applyLimit([^\;]+)\;/ims', "\$pages->setPage ( \$page-1 );
\$afmodel->offset ( \$pages->offset )->limit ( \$pages->limit );", $subcontent );
// ActiveRecord::findAll转化成 ActiveQuery::all()
$subcontent = preg_replace ( '/' . $preg_object . '\s*\-\>(findAll|find\s*\(\s*\)\-\>)\s*\([^\;]*?\)\;/ims', "\$afmodel->all();", $subcontent );
// $model->getList进行特殊处理
$subcontent = preg_replace ( '/' . $preg_object . '\s*\-\>getList\s*\([^\;]*?\)\;/ims', "{$object}->getList(\$afmodel);", $subcontent );
// 所有andWhere 内多余的and进行剔除
$subcontent = preg_replace ( '/andWhere\s*\(\s*(\'|\")\s*and/ims', 'andWhere(\\1', $subcontent );
// 调试转化结果
// gddebug ( $subcontent );
// exit ();
$content = str_replace ( $matchs [0], $subcontent, $content );
}
return $content;
},
'/(url\(\'\w+\'\)\?\>)\/(\w+)\//ims' => '\\1&\\2=',
// 原find(where)调整成find()->where(where)->one()
'/\-\>find\s*\(([^\)]+)\)/ims' => '->find ()->where (\\1)->one ()',
// 原findAll(where)调整成find()->where(where)->all()
'/\-\>findAll\s*\(([^\)]+)\)/ims' => '->find ()->where (\\1)->all ()',
// count 替换成 find()->where()->count();
'/\-\>count\s*\(([^\)]+)\)/ims' => '->find ()->where (\\1)->count ()',
// deleteByPk转化成findOne()->delete();
'/\-\>deleteByPk\s*\(([^\)]+)\)/ims' => '->findOne(\\1)->delete ()',
// 页面url自动转化成全小写
'/(?:\W)url\s*\(\s*\'[^\']+\'/ims' => function ($path, $content) {
$content = preg_replace_callback ( '/url\s*\(\s*\'[^\']+\'/ims', '_strtolower', $content );
return $content;
},
// 控制器,动作,只首字母大写,后半部分全部小写
'/function\s*action(\w)\s*\(\s*\)/ims' => function ($path, $content) {
$content = preg_replace_callback ( '/function\s*action(\w+)\s*\(\s*\)/ims', '_ucfirst', $content );
return $content;
}
);
function _strtolower($matches) {
return strtolower ( $matches [0] );
}
function _ucfirst($matches) {
$action = strtolower ( $matches [1] );
// actions 为过滤器配置,不进行过滤处理
if ($action === 's') {
return 'function actions()';
}
return 'function action' . ucfirst ( $action ) . '()';
}
function getModelsByControllerPath($path) {
$models_dir = dirname ( dirname ( $path ) ) . '/models';
$list = FileTools::getCurList ( $models_dir );
if (! $list)
return array ();
$items = array ();
foreach ( $list as $item ) {
$filename = basename ( $item );
$classname = str_replace ( '.php', '', $filename );
$items [$classname] = $classname;
}
return $items;
}
function getViewsByControllerPath($path) {
$ctlName = basename ( str_replace ( 'Controller.php', '', $path ) );
$ctlName = strtolower ( $ctlName );
$models_dir = dirname ( dirname ( $path ) ) . '/views/' . $ctlName;
$list = FileTools::getCurList ( $models_dir );
if (! $list)
return array ();
$items = array ();
foreach ( $list as $item ) {
$filename = basename ( $item );
$classname = str_replace ( '.php', '', $filename );
$items [$classname] = $item;
}
return $items;
}
function getNamespaceByPath($path) {
global $root_path;
$path = dirname ( $path );
$path = preg_replace ( '/\//', '\\', $path );
return str_replace ( $root_path, '', $path );
}
// sql 中,pow需要手动检查,替换成 power ,pi 需要手动检查,替换成 acos(-1)
$preg_file = array (
'/^\w+Module\.php$/' => 'Module.php'
);
FileTools::replacenames ( $path, $preg_file );
FileTools::replaceContents ( $path, $preg_contents, array (
'/\.php$/i' => false,
'/yiic/i' => true
) );
//直接根据列表文件进行替换规则处理
模块自动转化工具
/*******************************************************************************
* @author caihaibin <243008827@qq.com>
* @version 1.1.1
*******************************************************************************/
(function($) {
function getTxt(target) {
if($(target).prop("tagName") == 'INPUT') {
return $(target).val();
} else {
return $(target).html();
}
}
/**
* 根据按钮类型,自动识别文本字段来自value还是html
* @param {targetect} target
*/
function setTxt(target, txt) {
if($(target).prop("tagName") == 'INPUT') {
//恢复文本
$(target).val(txt);
} else {
//恢复文本
$(target).html(txt);
}
}
/**
* 停止计时器
*/
function stop(target) {
//恢复按键文本
setTxt(target, $.data(target, 'countdown').data.text);
//恢复点击
$(target).removeAttr('disabled');
//清除计时器对象
clearInterval($.data(target, 'countdown').data.time_id);
}
function bindEvents(target) {
//绑定点击事件
//click.xxx为命名空间形式,可以通过unbind('.xxx')一次性解除所有该命名空间下的绑定
//取消原".countdown"命名空间下,所有绑定事件
$(target).unbind('.countdown');
//直接绑定新事件
$(target).bind('click.countdown', function() {
var time = $.data(target, 'countdown').options.time;
//禁止二次点击
$(target).attr('disabled', 'disabled');
//获取计时器标志(int类型)
var time_id = setInterval(function() {
if(time <= 0) {
//统一调用计时器插件结束动作
$(target).countdown('stop');
$.data(target, 'countdown').options.onEnd();
return;
}
$.data(target, 'countdown').options.onShowtime(target, time, time + '秒');
//显示倒计时结果
setTxt(target, time + '秒');
time--;
}, 1000);
//记录计时器标志到对象数据中,用于计时结束时,clear动作
$.data(target, 'countdown').data.time_id = time_id;
});
}
/**
* 初始化计时器插件
* @param {Object} options
*/
function create(target) {}
/**
* parse options from markup.
*/
function parseOptions(target) {
var t = $(target);
return $.extend({}, {
//如果参数内容为空或undefined,不会覆盖前面的内容.如果有值,依次会覆盖前面数组的具体键值
time: t.attr('time') ? t.attr('time') : undefined
});
}
$.fn.countdown = function(options, param) {
if(typeof options == 'string') {
var method = $.fn.countdown.methods[options];
if(method) {
return method(this, param);
}
$.error('Method ' + options + ' does not exist on jQuery.countdown');
}
options = options || {};
return this.each(function() {
//实现针对每元素级的函数和变量
var state = $.data(this, 'countdown');
if(state) {
//二次初始化,只覆盖变量,重新绑定事件等..
$.extend(state.options, options);
} else {
state = $.data(this, 'countdown', {
//该对象所有选项,包括配置参数,传入配置,都存放在options
//如果参数内容为空或undefined,不会覆盖前面的内容.如果有值,依次会覆盖前面数组的具体键值
options: $.extend({}, $.fn.countdown.defaults, parseOptions(this), options),
//该对象所有临时变量
data: {
//按钮文本内容,用于复原
text: getTxt(this),
//计时器标志,用于clear时,触发
time_id: 0
}
});
}
//创建元素,只针对元素部分的调整.需要区分事件和元素的操作
create(this);
//绑定相关事件,可重复绑定;重复绑定时,通过事件命名空间进行解除
bindEvents(this);
});
};
//开放给外部调用动作
//注:函数内部需要二次调用闭包中所定义函数,jq对象为数组,请求的闭包中的函数动作是单体.
$.fn.countdown.methods = {
//解析出参数配置
parseOptions: function(jq) {
//参数只需要一份,列表对象中参数相同,所以只需要返回首个
return parseOptions(jq[0]);
},
//返回所配置参数
options: function(jq) {
//参数只需要一份,列表对象中参数相同,所以只需要返回首个
return $.data(jq[0], 'countdown').options;
},
//停止计时动作
stop: function(jq) {
return jq.each(function() {
stop(this);
});
}
};
//外部参数配置,允许参数和函数事件等
$.fn.countdown.defaults = {
/**
* 默认时长
*/
time: 60,
/**
* 计时事件
* @param {Object} target
* @param {Object} time 当前秒数
* @param {Object} txt 秒数文本
*/
onShowtime: function(target, time, txt) {},
/**
* 结束事件
* @param {Object} target
*/
onEnd: function(target) {}
};
})(jQuery);
<!DOCTYPE html>
<html>
<head>
<title>计时器测试</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<script src="scripts/jquery.js"></script>
<script src="scripts/jquery.countdown.js"></script>
</head>
<body>
<button time="3">3秒倒计时</button>
<button onclick="$('button[time]').countdown('stop')">取消倒计时</button>
<input type="button" value="60秒倒计时">
<button onclick="$('input[type=button]').countdown('stop')">取消倒计时</button>
<a time="3">a倒计时</a>
<script>
$(function() {
$('input[time],button[time]').countdown({
onShowtime: function(target, time, txt) {
console.log(time, txt);
},
onEnd: function(target) {
console.log('end');
}
});
$('a[time]').countdown();
// $('a,button,input').css('pointer-events', 'none');
})
</script>
</body>
</html>
三终于完成了,但还是要找时间回头复习,继续巩固熟练
再花一年搞定4,然后再集中花时间锻炼发音听力,最后就是广泛阅读.
想想现在好像没什么变化,起码沟通还凑合吧…上连接,github上问问题,朋友群里,英文沟通也凑合.速度不快.
https://github.com/yiisoft/yii/issues/4182
现在只要有时间就看,生活的杂事还是那么多,不过现在花更多的时候,也更集中.看到晚上2点.中午也看,周末也看.早上为了不影响早上的工作,早上睡醒就去上班.
再努力一年~ !
工作博客的,后面都只记录标题了.都是解决过的问题…通过标题应该能回忆起解决流程…
效果图:

注:该插件是有道官方提供的,但是一些细节东西没处理好.提交了修改建议老是没鸟,就自己搞搞. 分享页面和相关功能进行了优化,有需要的朋友自便.不清楚的,再问我.
优化功能:
初始化,隐藏相关菜单,侧面菜单(觉得每次都要单独关闭一次,比较浪费时间).
最大化文本框(有道没有提供网页端的设置,客户端有).
粘贴富文本内容,自动过滤标签.保留回车符.
iframe 选中修复
默认字体+默认字体颜色进行设置(只有客户端能设置,但是客户端不兼容有道划词翻译[-.-#, 91 年的中年人了,老了,不看18px的字体,眼睛就不舒服,太鲜红的也不舒服~]).
补充滚动条记忆处理,刷新后,会自动滚动到最后的位置 (很容易出现因网络问题或服务器问题,导致网络链接断开[wifi下比较明显],会从头加载,对于长内容,每次找到目标都比较蛋碎…)
下载上面的插件,解压到本地.
按设置,勾选”开发者模式”

并加载解压后的目录.
需要自动过滤html的,需要在链接后面补充 &fillhtml=1 标志,即分享页面后面追加即可

默认字体+默认字体颜色进行设置
解压上述文件.
解压,拖到插件管理页面,进行安装.
然后补充如下设置
![]()
http://note.youdao.com/editor/collab/bulbeditor/bulb.min.04731db4.js
file://e:/soft/editor/bulb.min.04731db4.js
上面解压后的文件路径.
比较懒,现在不想动.不然把东西写成一个 ,加按钮什么的也是可以的…. ( ̄︶ ̄) 胖子就这样子~
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String qrcode;
try {
//java的urldecode会指定编码,需要设置为iso-8859-1,这样输出的才是二进制
qrcode = URLDecoder
.decode("%89PNG%0D%0Axxxxxx",
"ISO-8859-1");
//以下为二进制内容输出为图片,不可以直接用普通方式输出图片,会导致文件头加了些东西,导致图片破坏
ByteArrayInputStream bis = new ByteArrayInputStream(
qrcode.getBytes());
Iterator<?> readers = ImageIO.getImageReadersByFormatName("png");
// ImageIO is a class containing static convenience methods for
// locating ImageReaders
// and ImageWriters, and performing simple encoding and decoding.
ImageReader reader = (ImageReader) readers.next();
Object source = bis; // File or InputStream, it seems file is OK
ImageInputStream iis = ImageIO.createImageInputStream(source);
// Returns an ImageInputStream that will take its input from the
// given Object
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
Image image = reader.read(0, param);
// got an image file
BufferedImage bufferedImage = new BufferedImage(
image.getWidth(null), image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
// bufferedImage is the RenderedImage to be written
Graphics2D g2 = bufferedImage.createGraphics();
g2.drawImage(image, null, null);
File imageFile = new File("d://test.png");
ImageIO.write(bufferedImage, "png", imageFile);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
#注意当前脚本是python 3.6.x
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib,sys,re
import struct
#读取当前编码
print (sys.getdefaultencoding())
qrcode="xxxxxxxxxxxxxxxxxxxxxxxxxxx"
#php urlencode 同 python 的urlencode 差别是
#python的urldecode处理有两种 urllib.parse.unquote_plus 和 urllib.parse.unquote
#差别是 urllib.parse.unquote_plus 会将 "+" 调整为 " ".这是和php urldecode相同的方式
#但是普通urllib.parse.unquote处理会将内容进行编码,导致结果和要的冲突.文件本身已是二进制,直接读,写入就是文件,经过编码,文件就出问题
qrcode=qrcode.replace("+"," ")
#比较 plus 后的处理结果是否相同
print (urllib.parse.unquote(qrcode)==urllib.parse.unquote_plus(qrcode))
#原内容长度
print (len(qrcode))
#获取二进制内容长度,用于判断是否有漏缺
print (len(urllib.parse.unquote_to_bytes(qrcode)))
#将处理后的内容写入文件
file=open("test.png","wb")
file.write(urllib.parse.unquote_to_bytes(qrcode))
file.close();