// PLUGIN_INFO//{{{ var PLUGIN_INFO = xml` {NAME} browser act scenario semi-automatic. hogelog 0.0.7 2.3pre https://github.com/vimpr/vimperator-plugins/raw/master/scenario-actor.js || // hatena sample javascript <|| action: {and: [ {sleep: 5000}, {follow: '//a[@rel="prev"]'}, ]} ||< is syntax-sugar of >|| action: [{and: [ {sleep: [5000]}, {follow: ['//a[@rel="prev"]']}, ]}] ||< and action expressions are quoted by {begin: ...}. == TODO == - write more examples. - add more functions. - fix bugs. - a lot. ]]> `; //}}} (function() { const debugMode = true; const VariablesName = 'ScenarioActorVariables'; const VariablesLabelID = 'ScenarioActorVariablesLabelID'; let SCENARIO_DIR = liberator.globalVariables.scenarioDir || 'scenario'; var libly = liberator.plugins.libly; var $U = libly.$U; var logger = $U.getLogger('scenario-actor'); function ScenarioActor () { //{{{ let variables = storage.newMap('scenarioactor', {store: true}); function ScenarioContext(event) { //{{{ let triggeredEvent = event; let win = (event.target.contentDocument||event.target).defaultView; let self = { glet: function (name, value) { if((typeof name)!='string') throw [name, value]; variables.set(name, self.eval(value)); return value; }, gvar: function (name) { if((typeof name)!='string') throw [name, value]; return variables.get(name); }, begin: function () { let lastValue; for(let i=0,len=arguments.length;i