I tried the solution in Distinguish Chrome from Safari using jQuery.browser but it doesnt work. This solution does but i dont have any way of getting the real version numbers:
$.browser.chrome = $.browser.webkit && !!window.chrome;
$.browser.safari = $.browser.webkit && !window.chrome;
I need to detect the full version numbers so that i can block older versions of these (because their slow/buggy, not for features).
You could use straight Javascript:
if(navigator.userAgent.toLowerCase().indexOf('Chrome'))
{
var n=navigator.userAgent.split(" ");
var curVersion="";
for (var i = 0; i < n.length; i++)
{
if(n[i].indexOf("Chrome"))
{
curVersionTmp=n[i].split("/");
curVersion = curVersionTmp[1];
}
}
}
else if(navigator.userAgent.toLowerCase().indexOf('applewebkit'))
{
var n=navigator.userAgent.split(" ");
var curVersion="";
for (var i = 0; i < n.length; i++)
{
if(n[i].indexOf("Version"))
{
curVersionTmp=n[i].split("/");
curVersion = curVersionTmp[1];
}
}
}
http://www.useragentstring.com/pages/Safari/
Related
I have a custom module in file help.js, the function name there is getfriends(req,res,next,user). The user is whose friends I want to get.
for (var i = 0; i < users.length; i++) {
for (var j = 0; j < docs.length; j++) {
if (docs[j].user1 == users[i].username) {
if (docs[j].user1 != req.body.user) {
friends.push(users[i]);
}
} else if (docs[j].user2 == users[i].username) {
if (docs[j].user2 != req.body.user) {
friends.push(users[i]);
}
}
}
if (i == users.length-1) {
console.log("friends",friends); //it displays my desired result and so I think the return is successfull
return(friends);
}
}
Now where I receive the data, I do this and data is not being displayed.
console.log(Help.getfriends(req,res,next,req.session.user));
I have tried doing :-
somevar = Help.getfriends(req,res,next,req.session.user);
console.log(somevar);
The module is being called, it is displaying perfect result. Please guide me how to get the data properly from the custom module.
Also, above I have done,
var Help = require('./help');
Your function is asynchronous.
When you console.log(...) <== there is no result yet.
So i'ts expected that you console.log undefined.
More info about nodejs asyncronous nature.
I used the following TreeWalker as a template from this post https://stackoverflow.com/a/37178130/7102491 and modified it to skip the element 'script', to prevent certain pages like a google search from breaking to no avail. Does anyone know how I can change the code to prevent breaking certain pages? Thanks.
var replaceArry = [
[/b/gi, 'better'],
[/Terms of service/gi, 'Términos y condiciones'],
[/Privacy policy/gi, 'Privacidad'],
// etc.
];
var numTerms = replaceArry.length;
var txtWalker = document.createTreeWalker (
document.body,
NodeFilter.SHOW_TEXT,
{ acceptNode: function (node) {
//-- Skip whitespace-only nodes
if (node.nodeValue.trim() && node.parentNode.nodeName != 'SCRIPT')
return NodeFilter.FILTER_ACCEPT;
return NodeFilter.FILTER_SKIP;
}
},
false
);
var txtNode = null;
while (txtNode = txtWalker.nextNode () ) {
var oldTxt = txtNode.nodeValue;
for (var J = 0; J < numTerms; J++) {
oldTxt = oldTxt.replace (replaceArry[J][0], replaceArry[J][1]);
}
txtNode.nodeValue = oldTxt;
}
For this issue, I have traced execution of setting svg content in svgcanvas.js file of svg editor, but no luck. I have even tried to remove g tags in "text2xml" call, but no luck.
please help me out...
Following code i have tried, here i have uploaded svg file and read that file through reader:
reader.onloadend = function(e) {
var xmlString=e.target.result;
xmlDoc = $jq.parseXML(xmlString);
var xmlElements=xmlDoc.documentElement.childNodes;
var reXmlElements=new Array();
var j=0;
for (var i=0; i<xmlElements.length; i++) {
if(xmlElements[i].nodeName=="g") {
//xmlElements[i].remove();
reXmlElements[j]=xmlElements[i].children[0];
j++;
} else {
//reXmlElements[j]=xmlElements[i];
}
}
xmlDoc.documentElement.children=reXmlElements;
console.log(xmlDoc.documentElement.children);
console.log((new XMLSerializer()).serializeToString(xmlDoc));
svgCanvas.setSvgString(e.target.result);
Thanks, I have solved this issue by doing following stuff:
svgCanvas.setSvgString(e.target.result);
svgEditor.changeZoom({value: (100*zoomlevel)});
//setSvgConfiguration(imprintWidth[side], imprintHeight[side], imprintLeft[side], imprintTop[side]);
document.querySelector("#svgcontent").setAttribute("overflow","hidden");
maxWidth=document.querySelector("#svgcontent").getAttribute("width");
maxHeight=document.querySelector("#svgcontent").getAttribute("height");
if($jq("#svgcontent g").length > 0 && $jq("#svgcontent g").children().length > 0) {
var allElements = $jq("#svgcontent g").children();
$jq("#svgcontent g:first").html("");
for(var i=0; i<allElements.length; i++) {
var element = allElements[i];
if(element.tagName == "g") {
for(var j=0;j<element.children.length;j++) {
$jq("#svgcontent g:first").append(element.children[j]);
}
}
}
allElements = $jq("#svgcontent g").children();
Is it possible to create an Excel format file from a Google sheet using Google script, so that it can be added as an attachment to an email?
I've got a code that takes columns with certain names (e.g. A, C, F) and turns them into a new sheet (on createCustomStatusTable() function).
https://docs.google.com/spreadsheets/d/1fZ0JMYjoIrfPIxFBVgDNU0x5X0ll201ZCU-lcaTwwcI/edit?usp=sharing
var expected = ['A','C','F'];
var newSpreadSheet = SpreadsheetApp.getActiveSheet();
var tableLastRow = newSpreadSheet.getLastRow();
var tablelastColumn = newSpreadSheet.getLastColumn();
var values = newSpreadSheet.getRange(1, 1, tableLastRow, tablelastColumn).getValues();
var rangeToCopy = [];
function in_array(value, array)
{
for(var i = 0; i < array.length; i++)
{
if(array[i] == value) return true;
}
return false;;
};
function columnsCount() {
var count = 1;
for (var i = 0; i < SpreadsheetApp.getActiveSheet().getLastColumn(); i++) {
if (in_array(values[0][i],expected))
count++;
}
return count;
};
function returnRange() {
for (var i = 1; i < SpreadsheetApp.getActiveSheet().getLastColumn()+1; i++) {
if (in_array(values[0][i-1],expected)) {
rangeToCopy.push(newSpreadSheet.getRange(1, i, newSpreadSheet.getMaxRows()));
};
};
return rangeToCopy;
};
function createCustomStatusTable() {
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Target');
for (var i = 1; i < columnsCount(); i++) {
returnRange()[i-1].copyTo(targetSheet.getRange(1,i));
};
};
Thank you in advance for any help
You can create an EXCEL type file with DriveApp:
The problem is, that the content must be a string. And I haven't tested for a way to make that work.
I know this doesn't answer your question. Hopefully someone knows for sure how to create an EXCEL file from a Google Sheet.
I understand that currently Dart doesn't have an explicit way to remove objects from memory and that objects that are no longer referenced anywhere are removed automatically.
Yet I've been running some benchmarking. Here's the code:
import 'dart:html';
import 'dart:async';
var components = [];
var times_to_run = 10;
class MockComponent {
Element element = new Element.html('<table></table>');
remove() {
element.remove();
element = null;
}
}
createAndRemoveComponents(t) {
var n = 50000; // number of objects to create and delete in this run
print("***Run #${times_to_run}");
print("creating $n objects...");
for(var i=0; i < n; i++) {
components.add(new MockComponent());
}
print("...done");
print("removing $n objects...");
while(components.length > 0) {
components.removeAt(0).remove();
}
print("...done");
times_to_run -= 1;
if(times_to_run <= 0) {
components = null;
t.cancel();
}
}
void main() {
new Timer.periodic(const Duration(seconds: 10), createAndRemoveComponents);
}
I made a video of this code running, so please take a look and see for yourself that memory actually leaks: http://www.youtube.com/watch?v=uVD8Npvc9vQ