'use strict';
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
function run(command) {
var pr = exec(command);
//pr.stdout.pipe(process.stdout);
//pr.stderr.pipe(process.stderr);
pr.stdout.on('data', function (data) {
process.stdout.write(data);
});
pr.stderr.on('data', function (data) {
process.stderr.write(data);
});
}
function optImages(files) {
require('mkdirp').sync('raw');
const rawFolder = path.normalize(process.cwd() + '/raw/');
files.forEach(function (file) {
let filePathParts = path.parse(file);
let rawPath = rawFolder + filePathParts.base;
fs.access(rawPath, function (err) {
if (err) {
let format = filePathParts.ext.substr(1);
if (format == 'png') {
run('@COPY "' + file + '" /B "' + rawPath + '" /B >> nul && @pngquant --force --skip-if-large --speed 1 256 --output "' + file + '" "' + rawPath + '" && @PNGZopfli "' + file + '" 10 "' + file + '" && echo complete: "' + file + '"');
} else if (format == 'jpg' || format == 'jpeg' || format == 'jpe' || format == 'jfif') {
run('@COPY "' + file + '" /B "' + rawPath + '" /B >> nul && @jpegtran -copy none -optimize -progressive "' + rawPath + '" "' + file + '" && echo complete: "' + file + '"');
}
}
});
});
}
if (process.argv.length >= 3) {
optImages(process.argv.slice(2));
} else {
glob(process.cwd() + '/@(*.png|*.jpg|*.jpeg|*.jpe|*.jfif)', function (err, files) {
if (err) {
console.error(err);
process.exit(1);
} else {
if (files.length > 0) {
optImages(files);
}
}
});
}
которые управляются простыми ползунками
WYSIWYG
пользователи присваивают текстовым параграфам различные css классы
sms.ru , который видимо закрылся.
function getLastMessageBody(thread){
var msgs = thread.getMessages();
var msg = msgs[msgs.length - 1].getBody();
return (/<em>(.+)<\/em>/i).exec(msg.replace(/\s+/gim,' '))[1];
}
function trimForSMS(text, mchars){
mchars = mchars || 0;
text = text.trim();
var maxLetters = ( /^[a-zA-Z0-9\s\^\[\]\(\)\/\*\+\-\=\|\{\}\%\,\$\#\@\&\!\?\.\,\`\~\;\:\_\<\>\"]*$/.test(text) ? 160 : 70 ) - 12 - mchars;
return text.substring(0,maxLetters).trim();
}
function my_notification()
{
var labels = GmailApp.getUserLabelByName('SMSnotify');
if(labels)
{
var threads = labels.getThreads();
if(threads.length > 0)
{
for(i in threads)
{
var cthread = threads[i];
var text = cthread.getFirstMessageSubject();
if(text[0] == 'R' && text[1] == 'e' && text[2] == ':')
{
text = text.substring(3);
}
text = trimForSMS(text);
if(text == 'Новое сообщение в заказе на FL.ru')
{
text = 'FL.ru: ' + trimForSMS(getLastMessageBody(cthread), 7);
}
UrlFetchApp.fetch('http://sms.ru/sms/send?api_id=<ваш ключ>&to=9176696749&text=' + encodeURIComponent(text));
}
labels.removeFromThreads(threads); //снимаем метки "SMSnotify" с цепочек
}
}
}