Display a waiting gif during a javascript function - javascript

I write a script to get a text file, to modify this texter file and then I import the file in our software.
The problem is that the import of the file is very slow (just this part of the script could take more than 1 minute sometime).
I would like to display a waiting gif during this process, so the user can see that the process is running, and he need to wait.
Some precision:
- It's only a javascript file with no html page
- The script is launched with a button in our software and I have access to ActiveXObject if necessary
Here is a sample code :
function importFec()
{
var iOpenDlg = 1;
var sPath = "Deskop";
var sTypes = "Fichier Texte (*.txt)|*.txt";
var sExt = "txt";
//Allow me to select a file in Windows
cheminFEC = fileDialog(iOpenDlg, sPath, sTypes, sExt);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1;
var f1 = fso.OpenTextFile(cheminFEC, ForReading);
var texte = f1.ReadAll();
var tableauFEC = [];
var tableauTest = [];
tableauFEC = texte.split(/\r\n/);
tableauTest = tableauFEC[0].split("\t");
var delimiter = "\t";
if (tableauTest.length == 1)
{
tableauTest = tableauFEC[0].split("|");
var delimiter = "|";
}
var nbColonne = tableauTest.length;
for (var i=0;i<tableauFEC.length;i++)
{
var tab = tableauFEC[i].split(delimiter);
tableauFEC[i] = new Array(25);
for (var j=0;j<nbColonne;j++)
{
tableauFEC[i][j] = tab[j];
}
}
//Make some change in the table to adapt my texte file
//Then create a new texte file C:\\FichierFEC\\FECModifie.txt
createNewFEC(tableauFEC);
var cwfConfiguration = Application.ApplicationInfo("ProgramPath")+"\\Library\\ImportFEC\\ImportFEC23032017.vgl"
var oImport = Import(ipASCII)
oImport.ImportComponents = CWImportComponents.icGeneralLedger
oImport.ASCIILayoutFile = cwfConfiguration
oImport.ASCIIDataFile = "C:\\FichierFEC\\FECModifie.txt"
//This is the function which take a long moment to execute
oImport.RunImport()
}
Thanks for your answer and explanation

I finnaly found another solution.
At the beggining of my script, I launch a .hta file with a GIF and a small texte.
At the end of my script, I close the .hta file
Thanks

Related

Copy a variable from the console to the clipboard

I created a spreadsheet to keep track of all the videos uploaded by the YouTubers I follow. Then, I created a script to be executed from the console that lists all the videos of that user. I store the list in a variable, and then I log it, select it, and copy it to the clipboard, but I'd like to copy it automatically every time I run the script. The problem is that the text is not inside an element (like a div, or textarea), so I can't use either window.navigator.clipboard or document.execCommand('copy').
Is there a way to do that?.
Thanks & greets from Argentina (Hope it is from England someday).
IDsign4U (Marcelo Miguel Bazan).
This is the code I use (open the videos tab in any channel and try it):
console.clear();
console.log("Título + Duración + Estado + URL en Subscripciones (sin número de orden)");
var domains = "";
var i = "";
var text = "";
var title = "";
var duration = "";
var hours = "";
var link = "";
var video = "";
var textDuration = "";
var hoursCheck = "";
var finalDuration = "";
var finalTitle = "";
domains = document.getElementsByTagName('ytd-grid-video-renderer')
for (i = 0; i < domains.length; i++)
{title = domains[i].getElementsByTagName('h3');
duration = domains[i].getElementsByTagName('span');
link = domains[i].getElementsByTagName('a');
textDuration = duration[0].innerText.trim();
hoursCheck = "";
hoursCheck = textDuration.length > 5 ? "0": "00:";
finalDuration = hoursCheck + textDuration + "\t" + "P" + "\t";
finalTitle = title[0].innerText + "\t";
url = "https://www.youtube.com" + link[0].attributes['href'].value;
video = video + finalTitle + finalDuration + url + "\n";}
console.log(video);
Why shouldn't you be able to use navigator.clipboard? It works fine while providing variables to copy to clipboard.
document.getElementById("copy").addEventListener("click", async () => {
const text = "Text copied to the clipboard"
await navigator.clipboard.write(text)
})
<button id="copy">
Copy to clipboard
</button>
When you say "from the console", do you mean the browser console? If so, there's a built-in global copy function (not window.copy, just copy).
Yes!! Thank you Zac (and wOxxOm and Jannis Ioannou) for the answer.
It's just a matter of deleting the, for me, weird DOM element with the ID 'copy' to be able to use the copy function in the console.
Thanks & greets from Argentina (Hope it is from England someday).
IDsign4U (Marcelo Miguel Bazan).

Chrome extension : Get discord webhooks content when it is posted in a channel

I made a little chrome extension which take webhook contents as parameters.
Here's the content_script.js of my extension :
f = function(){
var test = $( "div.embedDescription-1Cuq9a:last" ).text();
var cs_rep_1 = test.split('1 : "');
var cs_rep_1 = cs_rep_1[1].split('"');
var cs_rep_1 = cs_rep_1[0];
var cs_rep_2 = test.split('2 : "');
var cs_rep_2 = cs_rep_2[1].split('"');
var cs_rep_2 = cs_rep_2[0];
var cs_rep_3 = test.split('3 : "');
var cs_rep_3 = cs_rep_3[1].split('"');
var cs_rep_3 = cs_rep_3[0];
var totalElements = '&cs_rep_1='+cs_rep_1+'&cs_rep_2='+cs_rep_2+'&cs_rep_3='+cs_rep_3;
chrome.runtime.sendMessage({total_elements: totalElements});
}
document.body.addEventListener('dblclick',f);
As you can see it is triggered only if I double click in the tab where the webhook is posted.
I'd like to trigger it when a new webhook is posted, that's to say when a new div with this the class embedDescription-1Cuq9a is created in the tab.
Any ideas on how to do this ?

How to set byte[] property of ActiveX component from Javascript?

I'd like to set RTF formatted calendar entries, but don't know how to pass the byte[] to the ActiveX object, i.e. the RTFBody property.
The following code reads the RTFBody property after some content has been set - so reading the byte[] is working, but when I try to write exactly the same content (+ trailing 0) back, neither an U/Int8Array nor a Scripting.Directory works.
Maybe it's possible to workaround with some .NET objects, but I don't know how to instanciate those Non-ActiveX components. An alternative solution shouldn't require to script the formattings, e.g. "go to line 2 and make it bold", i.e. I like to generate the rtf via a template and only paste the result into the calendar object.
I'm aware that this has to be eventually encoded in Windows-1252, but for a start I simply want to see the same bytes to be written successfully. The script is executed within a HTA context - so script security is not an issue.
<html>
<head>
<hta:application id="foo" applicationname="foo" version="1" navigable="yes" sysMenu="yes"></hta>
</head>
<script language="JavaScript" type="text/javascript">
function doit2() {
var rtfBody =
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\nouicompat\\deflang1031{\\fonttbl{\\f0\\fswiss\\fcharset0 Calibri;}}\r\n"+
"{\\*\\generator Riched20 14.0.7155.5000;}{\\*\\mmathPr\\mwrapIndent1440}\\viewkind4\\uc1\r\n"+
"\\pard\\f0\\fs22 bla\\par\r\n"+
"}\r\n";
// https://github.com/mathiasbynens/windows-1252
var rtfBody1252 = rtfBody; // windows1252.encode(rtfBody);
var dict = new ActiveXObject("Scripting.Dictionary");
for (var i = 0; i < rtfBody1252.length; i++) {
dict.add(i, rtfBody1252.charCodeAt(i));
}
dict.add(rtfBody1252.length, 0);
// Alternative setting via U/Int8Array also doesn't work ...
// var buf = new ArrayBuffer(rtfBody1252.length+1);
// var bufView = new Int8Array(buf);
// for (var i=0, strLen=rtfBody1252.length; i<strLen; i++) {
// bufView[i] = rtfBody1252.charCodeAt(i);
// }
// bufView[rtfBody1252.length] = 0;
var myOlApp = new ActiveXObject("Outlook.Application");
var nameSpace = myOlApp.GetNameSpace("MAPI");
var recipient = nameSpace.CreateRecipient("user#host.com");
var cFolder = nameSpace.GetSharedDefaultFolder(recipient,9);
var appointment = cFolder.Items.Add(1);
appointment.Subject = "Subject";
appointment.Location = "Location";
appointment.Start = "22.02.2017 17:00";
appointment.Duration = "120";
appointment.Categories = "deleteme";
appointment.Body = "bla";
var va = new VBArray(appointment.RTFBody).toArray();
var bla = String.fromCharCode.apply(null, va);
document.forms[0].output.value = bla;
// var bla2 = windows1252.decode(bla);
appointment.RTFBody = dict.Items();
appointment.ReminderSet = "true";
appointment.Save();
entryId = appointment.EntryId;
appointment.Display();
delete appointment;
delete cFolder;
delete recipient;
delete nameSpace;
delete myOlApp;
}
</script>
<body>
<form>
<input type="button" onclick="doit2()" value="doit"/>
<textarea name="output" rows="5" cols="50"></textarea>
</form>
</body>
</html>

Prevent PDF from auto-downloading and have it Auto Print instead

I have a situation where when a user is viewing their order history, they are provided a link to print a PDF version of their invoice. Currently when the user clicks on the link the PDF will automatically download to their computer.
The 'higher-ups' are wanting that to be changed, so when the user clicks the link to print the pdf, a print dialogue box will appear instead of automatically downloading the PDF.
I've been able to get the pdf open in a new window but when ever the pdf is being called it won't display the pdf but will automatically download it instead.
I've searched all over the internet and SO for a solution but have yet to yield any results. This needs to be done, if possible, via JavaScript or jQuery.
HTML
<p><a id="print_pdf" target="_blank">Click to Print Invoice</a>
JavaScript / jQuery
var print_pdf_link = $('#print_pdf').attr('href');
var linkNo2 = "privatefile.dhtml~useridtext~&file=~username~_rep.pdf";
$('#print_pdf').click(function(){
w = window.open(linkNo2);
w.print();
});
I've also used:
<a href="#" onclick="window.open('privatefile.dhtml~useridtext~&file=~username~_rep.pdf', '_blank', 'fullscreen=yes'); return fal
se;">MyPDF</a>
* please note the text between tilde are placeholders that contain values from the back-end
Thanks for your help!
Try it i hope i would make use of.
var pfHeaderImgUrl = '';
var pfHeaderTagline = '';
var pfdisableClickToDel = 0;
var pfHideImages = 0;
var pfImageDisplayStyle = 'right';
var pfDisablePDF = 0;
var pfDisableEmail = 0;
var pfDisablePrint = 0;
var pfCustomCSS = '';
var pfBtVersion = '1';
(function() {
var js, pf;
pf = document.createElement('script');
pf.type = 'text/javascript';
if ('https:' === document.location.protocol) {
js = 'http://domain.com//main.js'
} else {
js = 'http://domain.com/printfriendly.js'
}
pf.src = js;
document.getElementsByTagName('head')[0].appendChild(pf)
})();
<a href=""
style="color:#6D9F00;text-decoration:none;"
class="printfriendly"
onclick="window.print();return false;"
title="Print">Print</a>

SharePoint List Button that browses for files and folders, then puts path and file names in SharePoint List Column WITHOUT using ActiveX

I am trying to create a button using SharePoint designer that onclick will allow users to browse folders and then put the contents (path:\filenames) into a sharepoint list column. I have used the below code and it works except I need a solution that does NOT use activeX as my system is set to not allow unsigned activex. I am open to any solution that will work on a sharepoint list that does not use and activex control. My button onclick="getFolderFiles()"
function getFolderFilesSub(fsoFolder, astrFolderFiles) {
var eFiles = new Enumerator(fsoFolder.Files);
eFiles.moveFirst();
While (eFiles.atEnd() ==false) {
astrFolderFiles.push(eFiles.item().Path);
eFiles.move.next();
}
var eSubFolders = new Enumerator(fsoFolder.SubFolders);
eSubFolders.moveFirst();
while (eSubFolders.atEnd() == false({
getFolderFilesSub(eSubFolders.item(), astrFolderFiles);
eSubFolders.moveNext();
}
}
function getFolderFiles() {
var objShell = new ActiveXObject('Shell.Application');
var objShellFolder = objShell.BrowseForFolder(0, 'Choose a folder', 0, 0);
if (objeShellFolder != null) {
var fso = new ActiveXObject('Scripting.FileSystemObject');
var fsoFolder = fso.GetFolder(objShellFolder.Items().Item().Path);
astrFolderFiles = new Array();
getFolderFilesSub(fsoFolder, astrFolderFiles);
if (astrFolderFiles.length != 0) {
var strFolderFiles = astrFolderFiles[0];
for (var i=1; i <= astrFolderFiles.length-1; i++) {
strFolderFiles = (strFolderFiles + '\n\ + astrFolderFiles[i];
}
document.getElementById(ct100$PlaceHolderMain$g_85cf34cd_8dc3_47ca_85d9_
a6f47297db56$ffFileNames$ct100#ct100$text
field").value = strFolderFiles;
}
}

Categories