function parseSearch() {
const search = location.search.slice(1);
return search.split('&').reduce((params, pair) => {
const [key, value] = pair.split('=');
params[decodeURIComponent(key)] = decodeURIComponent(value);
return params;
}, {});
}
document.addEventListener('DOMContentLoaded', () => {
const container = document.getElementsByClassName('button-container')[0];
if(container && parseSearch().url) {
container.innerHTML = '<button type="button" onclick="window.open(\'http://site3.ru/\'+location.search)">перейти</button>';
}
});
<div class="button-container"></div>
function requestAsync(params) {
return new Promise((resolve, reject) => {
request(params, (err, response, body) => {
if(err) { return reject(err); }
resolve({response, body});
});
});
}
async function getURL(_url) {
var data, url = _url;
do {
const {body} = await requestAsync({url});
data = JSON.parse(body);
url = _url + '&pageToken=' + data.nextPageToken;
} while(data.nextPageToken !== undefined);
return data;
}
'use strict';
const fs = require('fs');
const compiler = require('vue-template-compiler');
require.extensions['.vue'] = (module, filename) => {
let file = fs.readFileSync(filename, 'utf8');
let {script, template} = compiler.parseComponent(file);
let {render, staticRenderFns} = compiler.compile(template.content);
let result = `(function(){'use strict';${script.content}})();Object.assign(module.exports,{render:function(){${render}},staticRenderFns:[${staticRenderFns.map(code => {
return `function(){${code}}`;
}).join(',')}]});`;
module._compile(result, filename);
};
new Vue(require('./App.vue'))
function doLater(cb) {
const d = {resolve: null, reject: null};
const promise = new Promise((resolve, reject) => {
d.resolve = resolve;
d.reject = reject;
});
function run() {
try {
cb(d.resolve, d.reject);
} catch(e) {
Promise.reject(e).catch(d.reject);
}
}
return {run, promise};
}
//example:
const d = doLater(ok => {
console.log('1');
ok();
});
console.log('2');
d.promise.then(() => {
console.log('3');
});
d.run();