Google Docs and Ms Word apps not showing in chooser - javascript

In my app I have a link to a docx file located on an server. I want to show this file in another app that can show docx files, like Google Docs or Microsoft Word.
When I display the chooser, neither Google Docs or Microsoft Word are shown (and yes they are installed), it is only the OfficeSuite app that is shown.
Anyone knows why this is?
This is my code:
var uri = android.net.Uri.parse(httpUrlString);
var extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(uri.toString());
var mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
var intent = new android.content.Intent(android.content.Intent.ACTION_VIEW);
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NO_HISTORY);
if (extension === "" || mimetype == null) {
// if there is no extension or there is no definite mimetype, still try to open the file
intent.setDataAndType(uri, "text/*");
} else {
intent.setDataAndType(uri, mimetype);
}
var packageManager = application.android.context.getPackageManager();
var activities = packageManager.queryIntentActivities(intent, android.content.pm.PackageManager.MATCH_DEFAULT_ONLY);
var isIntentSafe = activities.size() > 0;
if (isIntentSafe) {
try {
application.android.startActivity.startActivity(android.content.Intent.createChooser(intent, "Åben Fil med"));
} catch (e) {
console.log(e);
}
}
I have tried it on a Sony, LG and a Samsung phone, its the same.

My guess here is that you have set a default app for files with extension *.docx and this default app is OfficeSuite.
As a potential workaround you can try to change the flag from MATCH_DEFAULT_ONLY to MATCH_ALL
you can also reset your default apps on your device
how-to-set-and-clear-a-default-app-on-an-android-device

Okay, so I think I found the reason.
It looks like Google Docs app and Microsoft Word app can't handle http-uri (http://...), but if I download the file to the phone and then parse a file-uri (file:///....) it works well.

Related

What all files do I need to publish for this extension, and will a computer without NodeJS be able to run it?

So I was making an extension using this template and I wanted to know what files i'll need to publish for the final extension. The extension converts texts to emoji, similar to discord, so when you type ": sob:" it converts it to 😭. I'm using NodeJS to download an emoji dictionary and so also wanted to know if itd work on a computer without this dictionary.
My code:
import emo from "emoji-dictionary";
let input_colon = false;
const look_for = /:([^\s]*):/gi;
document.body.addEventListener("input", (event) => {
Array.from(document.querySelectorAll("input, textarea")).forEach((input) => {
Array.from(input.value.matchAll(look_for)).forEach((emo_input) => {
const emoji = emo.getUnicode(emo_input[0]);
if (emoji == undefined) {
} else {
input.value = input.value.replace(emo_input[0], emoji);
}
});
});
To publish on browsers for production, you should zip source directory. Or to publish for test on your browser, you can just add source directory which has manifest, background or etc. The files to publish are manifest.json, content.js, background.js which are related to manifest.json.
For the template you can add ./distribution directory on chrome://extensions page after what you want to code. There shows the doc this.

Google picker make a copy when uploading

I have replicated the google file picker in a web app.
My question is how would I tell the google picker to make a copy of the file when uploading it to google drive ?
Any help would be much appreciated.
I realised that google picker could not do what I needed so Google App Script to the rescue.
Firstly you need to create a new google spreadsheet
Under "Tools->Script Editor" add the following code
Thought trial an error I came up with the following.
function copyFiles() {
var dApp = DriveApp; // Get the drive app
var folderIter = dApp.getFoldersByName('parentFolder'); //Get folder my id
var folder = folderIter.next(); // Get the first folder
var fileIter = folder.getFiles(); // File iterator
var storageFolder = folder.getFoldersByName('childFolder').next(); // Get target folder
var subFolderIter = storageFolder.getFiles(); // sub folder File iterator
while(fileIter.hasNext()) {
var file = fileIter.next(); // Get the current File
var fileName = file.getName();
// Check if the current file exists in a coped folder
// If false make a copy else do noting
// This check prevents duplicate, Becasue makeCopy generates uniques ID everytime
if(!storageFolder.getFilesByName(fileName).hasNext()) {
//Logger.log('Files does NOT exists');
file.makeCopy(storageFolder);
} else {
//Logger.log('Files does exists');
}
}
}
Hope this helps anyone who might need.
Note: You will need to set up triggers for the script to run when required

Save text to file within Chrome extension

I have a Firefox addon which is able to save a piece of text to a file on the user's hard-disk.
I've been doing some research on porting this part of functionality over to Google Chrome but looks like there is a lot of challenges, examples:
How can a Chrome extension save many files to a user-specified directory?
Is there a standardized way of achieving this functionality?
I am amazed at how difficult it is to implement something so trivial.
The suggested answer above is to basically implement an extension and packaged app, but this is not an option for me as it will be available to user on internet.
And having to install 2 separate entities seem arkward.
Sample of my Firefox addon code which saves text to a file in a directory of my choice.
I'm looking for the same kind of functionality except in Google Chrome ..
var ostream;
var file = Cc["#mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath('/home/rob/Desktop/');
file.append('Test.txt');
try{
if (file.exists() === false) {file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 420);}
ostream = FileUtils.openFileOutputStream(file, FileUtils.MODE_WRONLY | FileUtils.MODE_APPEND);
var converter = Cc["#mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
var istream = converter.convertToInputStream('This is my string of text');
// The last argument (the callback) is optional.
NetUtil.asyncCopy(istream, ostream, function(status) {
if (!components.isSuccessCode(status)) {
alert('error');
}else{
alert('success');
}
});
} catch (e) {
return false;
}

"log4javascript" logger to store in local file

We are currently using log4javascript-popUpAppender console for development and would like to store the details to local file.
Though we can use the AjaxAppender to send log messages to the server and log those messages to log4j set up with a rolling file appender, we are looking for a way to use something similar to FileAppender in Log4js.
Any idea/suggestion?
This is similar to http://www.techques.com/question/1-3626960/JavaScript-logger-into-a-rolling-file
Since we have already implemented log4javascript, we would like to stick with the same framework.
This is still not really viable in browsers, in my view. I've had another look at it; these are my observations:
In Firefox, I don't think it is currently possible to write to the local file system at all, even if the user approves. From Firefox 17 (I think), privileged code can no longer run in a web page, which rules out the old method floating around on the web (e.g. here)
IE still has its ActiveX method of doing this, but it's more locked-down than ever and requires various actions by the user to enable it.
HTML5 has a file system API which is currently only implemented by new versions of Chrome and Opera. It writes files to a carefully sandboxed location and offers no control over actual file name or path.
Safari currently has no way to do this, as far as I can tell.
In general, browsers sensibly offer little or no access to files on the local file system, so it's an unreliable way to log. However, I've written a rough BrowserFileAppender that implements the HTML5 and ActiveX methods which you're welcome to use if you find it helpful:
https://gist.github.com/timdown/6572000
Adding FileAppender solution for IE and Firefox.
function FileAppender() {}
FileAppender.prototype = new log4javascript.Appender();
FileAppender.prototype.layout = new log4javascript.SimpleLayout();
FileAppender.prototype.append = function(loggingEvent) {
var appender = this;
var getFormattedMessage = function() {
var layout = appender.getLayout();
var formattedMessage = layout.format(loggingEvent);
if (layout.ignoresThrowable()) {
formattedMessage += loggingEvent.getThrowableStrRep();
}
return formattedMessage;
};
writefile = function(destinationFile, message) {
if (isEmpty(destinationFile)) {
log.error("Source location unknown");
return;
}
if ($.browser.msie) {
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(destinationFile, 8, true);
file.WriteLine(message);
file.close();
} catch (e) {
log.error("Please validate if file exist");
}
} else {
netscape.security.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
this.fso.initWithPath(destinationFile);
if (!this.fso.exists()) {
// create file if needed
this.fso.create(0x00, 0600);
}
var file = Components.classes["#mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
file.init(this.fso, 0x04 | 0x08 | 0x10, 064, 0);
var line = message;
file.write(line, line.length); // write data
file.close();
}
};
getFile = function() {
return "c://temp//log//Javascriptlog.log";
};
writefile(getFile(), getFormattedMessage());
};
FileAppender.prototype.toString = function() {
return "FileAppender";
};
log4javascript.FileAppender = FileAppender;

Issues in developing web scraper

I want to develop a platform where users can enter a URL and then my website will open the webpage in an iframe. Now the user can modify his website by simply right clicking and I will provide him options like "remove this element", "copy this element". I am almost through. Many of the websites are opening perfectly in iframe but for a few websites some errors have shown up. I could not identify the reason so asking for your help.
I have solved other issues like XSS problem.
Here is the procedure I have followed :-
Used JavaScript and sent the request to my Java server which makes connection to the URL specified by the user and fetches the HTML and then use Jsoup HTML parser to convert relative URLs into absolute URLs and then save the HTML to my disk in Java. And then I render the saved HTML into my iframe.
Is somewhere wrong ?
A few websites are working perfectly but a few are not.
For example:-
When I tried to open http://www.snapdeal.com it gave me the
Uncaught TypeError: Cannot read property 'paddingTop' of undefined
error. I don't understand why this is happening..
Update
I really wonder how this is implemented? # http://www.proxywebsites.in/browse.php?u=Oi8vd3d3LnNuYXBkZWFsLmNvbQ%3D%3D&b=13&f=norefer
2 issues, pick any you like:
your server side proxy code contains bugs
plenty of sites have either explicit frame-break code or at least expect to be top level frame.
You can try one more thing. In your proxy script you are saving your webpage on your disk and then loading into iframe. I think instead of loading the page you saved on disk in iframe try to open that page in browser. All those sites that restirct their page to be loaded into iframe will now get opened without any error.
Try this I think it an work
My Proxy Server side code :-
DateFormat df = new SimpleDateFormat("ddMMyyyyHHmmss");
String dirName = df.format(new Date());
String dirPath = "C:/apache-tomcat-7.0.23/webapps/offlineWeb/" + dirName;
String serverName = "http://localhost:8080/offlineWeb/" + dirName;
boolean directoryCreated = new File(dirPath).mkdir();
if (!directoryCreated)
log.error("Error in creating directory");
String html = Jsoup.connect(url.toString()).get().html();
doc = Jsoup.parse(html, url);
links = doc.select("link");
scripts = doc.select("script");
images = doc.select("img");
for (Element element : links) {
String linkHref = element.attr("abs:href");
if (linkHref != "") {
element.attr("href", linkHref);
}
}
for (Element element : scripts) {
String scriptSrc = element.attr("abs:src");
if (scriptSrc != "") {
element.attr("src", scriptSrc);
}
}
for (Element element : images) {
String imgSrc = element.attr("abs:src");
if (imgSrc != "") {
element.attr("src", imgSrc);
log.info(imgSrc);
}
}
And Now i am just returning the path where i saved my html file
That's it about my server code

Categories

Resources