Clickable Url in Twitter - windows-phone-7

i have implemented a simple twitter reader in my app. I am able to get the tweets of a
user. But, if there is a url in this tweet, i cant click on it, as its not detected as an URL.
Is there a possibility to implement this function, so that urls in the tweet are displayed
as clickable url, and then launch for example a webbrowser?
Thank you very much

I assume you are using a TextBlock to show the tweet text, correct? If so, change it to a RichTextBox and all you need to do is use Run for text and Hyperlink for the links!
Also, make sure you set the IsReadOnly property of the RichTextBox to true in order for it to work properly!
Next, parse the tweet text with a regular expression to find links, and use the Hiperlink class to create a clickable link on it, and Run on the remaining text!
Here's a sample function that will parse a tweet and build the content for a RichTextBox:
private Block ParseTweet(string tweetText)
{
var paragraph = new Paragraph();
var lastIndex = 0;
foreach (Match m in Regex.Matches(tweetText, #"(http(s)?://)?([\w-]+\.)+[\w-]+(/\S\w[\w- ;,./?%&=]\S*)?"))
{
if (m.Index > 0)
paragraph.Inlines.Add(tweetText.Substring(lastIndex, m.Index));
var hyperlink = new Hyperlink()
{
NavigateUri = new System.Uri(m.Value, System.UriKind.RelativeOrAbsolute),
TargetName = "_blank"
};
hyperlink.Inlines.Add(m.Value);
paragraph.Inlines.Add(hyperlink);
lastIndex = m.Index + m.Length;
}
if (lastIndex < tweetText.Length)
paragraph.Inlines.Add(tweetText.Substring(lastIndex));
return paragraph;
}
You should call this function like so:
var tweetText = #"Testing: http://twitter.com -> link for twitter";
MyRichTextBox.Blocks.Add(ParseTweet(tweetText));

I think it's not possible but but you can parse your text to find URL (with regex) and display a hyperlink below the text.
1) you search for URLs in the text with a regex
2) if a URL is found, you create a HyperlinkButton with this URL

Related

Is there any way to get google classroom form question insert title image URL

I want to get the image url which is inserted when create a question into the classroom form.
Below is the code through we get the title , choices if available but i am not able to get the image url which is insert under the question title.
function getCourse() {
var form = FormApp.openById(id);
var formResponses = form.getItems();
var type=formResponses[0].getType();
var title = formResponses[0].getTitle();
var image =formResponses[0].getImage();//no such method Logger.log(image);
}
That image is not available through the Forms Service, it's added through the /viewresponse source code which is generated some way by Google. You could get it by using the URL Fetch Service (UrlFetchApp).
Related
How can I scrape text and images from a random web page?
(javascript / google scripts) How to get the title of a page encoded with iso-8859-1 so that the title will display correctly in my utf-8 website?
var blob = questionType.getImage();
var b64 = blob.getContentType() + ';base64,'+ Utilities.base64Encode(blob.getBytes());
var html = "data:" + b64 ;

Image duplicates itself when using appendParagraph in Google Script

I wrote a script to add an image from my Google Drive and some custom text to a Google Doc. (I got the image insertion code from here).
The resulting document is created ok, but my image is added twice for some reason...
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
body.appendParagraph('Test line of text for testing');
doc.saveAndClose();
}
However, if I get rid of my appendParagraph code (body.appendParagraph(t1);) I only get one image (but obviously without the paragraph of text I want)
What's going on here? And how do I add both one picture and my paragraph of text?
I have not even the slightest clue as to why, but I found a way to make this work.
Switching the order of my code seemed to do the trick. I simply moved the image-insertion code to the end (i.e., after the appendParagraph code), and it worked fine. No duplicate image!
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
body.appendParagraph('Test line of text for testing');
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
doc.saveAndClose();
}

Nativescript get value of textfield

In NativeScript, how can I get the value of a textfield using JavaScript (not TypeScript/Angular)?
XML:
I've tried various combinations of "getViewByID()" but nothing is working (perhaps I didn't "require" right libraries?). Not looking to do 2-way binding; just get the value (print to the console).
Just as a reminder, it's usually a good idea to share some code with your question to show what you have already tried.
In this example you could have shared some xml markup for instance.
Anyways to get the value of a textfield you would have something like this.
var view = require("ui/core/view");
function pageLoaded(args) {
var page = args.object;
var textfield= view.getViewById(page, "textfieldID");
}
After this you should be able to do :
var text = textField.text;

Count tabs with same title in Firefox add-on using Add-on SDK

I am trying to count firefox tabs with same specific title (like Google title) on Firefox add-on builder.
I know about
var tabs = require("tabs");
for each (var tab in tabs)
but how to get count number of tabs with same name?
Thank you in advance!
How do you get the titles of the tabs? Is this possible? Once you've worked that out, declare an object for storing title counts, where the title is the property.
ttabs_obj = ttabs_obj || {}; // your retrieved tabs
titles_count = titles_count || {};
ttabs_obj.forEach(function(tab, titles_count){
title = ''; //get title from tab here, replacing characters invalid in property names with '_'
if (!(title in titles_count)) {
titles_count[title] = 0;
}
titles_count[title] += 1;
});
This worked for me:
//Set up namespace
var app={};
app.tabs = require("sdk/tabs");
//Takes an array and returns an object.
//In this case, keys are tab titles and values are tab counts.
app.summarize=function(arr){
return arr.reduce(function(memo,item){
if (typeof memo[item]==='undefined'){
memo[item]=1;
}
else{
memo[item]++;
}
return memo;
},{});
};
//Whenever a tab loads, recalculate and output to console
//Need to enable console logging:
app.tabs.on('ready',function(){
//app.tabs is a pseudo-array. Convert to array
var tabsArr=Array.prototype.slice.call(app.tabs);
var tabsTitles=tabsArr.map(function(tab){
return tab.title;
});
console.log(app.summarize(tabsTitles));
});
The documentation for tabs is here:
https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
There were two problems: getting tab titles and getting the number of occurrences of each tab title. For getting tab titles, see:
https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
For getting the number of occurrences of each item in an array, see:
http://jsfiddle.net/cz2SG/
Note that in order to see the console logging you need to enable it:
https://blog.mozilla.org/addons/2013/03/27/changes-to-console-log-behaviour-in-sdk-1-14/

Mozilla Extension - tracking data per opened tab

In a firefox extension I'm temporarily saving data in javascript to show in a sidebar. When a tab is selected, I want to change the text in the sidebar to the right data. What is the best object to use as the "Identifier" for each tab? I'm trying to use the tab object. However, I'm stuck then on how to associate the data to the tab. Currently, I get a load event on the document in a tab. Then I process the data in the document. AFter showing the new data in the tab, I want to save it into a map with the tab as the key so that I can retrieve it on a SelectTab event. However, I'm not sure how to find the tab from the documentin the load event.
So please either tell me how to get the tab object from the document object, or a better thing to use as the key.
The following is one way I've found, but I'm sure there is something more elegant.
getTabForDocument : function (document) {
var wm = Components.classes["#mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
for (var found = false, index = 0, tabbrowser = wm.getEnumerator('navigator:browser').getNext().gBrowser;
index < tabbrowser.tabContainer.childNodes.length && !found;
index++) {
// Get the next tab
var currentTab = tabbrowser.tabContainer.childNodes[index];
if (currentTab.linkedBrowser.contentWindow.document == document)
{
return currentTab;
}
}
return null;
},
Thanks...
Take a look at: https://developer.mozilla.org/en/Code_snippets/Tabbed_browser, especially the gBrowser.selectedBrowser section and https://developer.mozilla.org/En/Listening_to_events_on_all_tabs
To associate data with a tab you can use the setUserData method on the browser.
To get the browser for a document use the getBrowserForDocument method on the gBrowser global object.

Resources