I have been trying to find a bookmarklet that will allow you to view a specific tweet in the twitter app. The API needed is twitter://status?id=124556789012345789 and it will open tweet id 124556789012345789 which is found in the URL. I need to pull the tweet id from the URL and add it to the twitter://status?id=. The problem, is that the URL with the tweet id in it is https://mobile.twitter.com/(username)/status/(tweet id) and the username can vary. I tried to do javascript:var s = (location.href);
var u = s.replace("https://mobile.twitter.com/*/status/", "twitter://status?id="));window.open(u); but the * in the username didn't act as an unknow variable, as it sometimes does. Any help would be greatly appreciated.
Tada! javascript:var a = (location.href); var b = a.split("/"); var c = b[5].replace("?photo=1",""); var d = ('twitter://status?id='+c); window.location = (d);
Related
I'm developing javascript add-on where part of functionality is reminder. User entered some data and set what this email will be sent for example tomorrow.
My idea/task is to make possible what on pressing for example btn in my add-in it will open in gmail the needed email.
What I have is id of the email that I need re-open in gmail.
Is it possible, if you know needed email id, in the gmail to open it again by add-in in separate window? Assuming you clicked btn in your add-on?
Any ideas?
btw I am using gmail api for my rest calls to app
Depending on what you want to accomplish, I'm thinking of two alternatives.
Open existing message in a new window:
Use setOpenLink or setOnClickOpenLinkAction to open a URL in a new tab when a button is clicked.
This tab can be full size or as a popup (via setOpenAs):
var message = GmailApp.getMessageById(messageId);
var url = message.getThread().getPermalink();
var openLinkButton = CardService.newTextButton()
.setText('Open link')
.setOpenLink(CardService.newOpenLink()
.setUrl(url)
.setOpenAs(CardService.OpenAs.OVERLAY));
var buttonSet = CardService.newButtonSet()
.addButton(openLinkButton);
var section = CardService.newCardSection()
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
return card.build();
Create and display a draft:
Use setComposeAction to create and display a draft as a popup when a button is clicked. This draft can be standalone or a response to whatever message id you provide.
For example, in the sample below, a draft is created and displayed when clicking the button Compose Reply:
function createCard(e) {
var composeAction = CardService.newAction()
.setFunctionName('createReplyDraft');
var composeButton = CardService.newTextButton()
.setText('Compose Reply')
.setComposeAction(
composeAction,
CardService.ComposedEmailType.REPLY_AS_DRAFT);
var buttonSet = CardService.newButtonSet()
.addButton(composeButton);
var section = CardService.newCardSection()
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
return card.build();
}
function createReplyDraft(e) {
// ...Get messageId ...
var message = GmailApp.getMessageById(messageId);
var draft = message.createDraftReply("I'm a draft!");
return CardService.newComposeActionResponseBuilder()
.setGmailDraft(draft).build();
}
Reference:
Gmail interactions
hello my question is what is the best approach to Restrict access to some urls of wordpress website to single referrer domain.
as far as I am familar with javascript I found a way for that. but I think javascript code is not good, because the source code of the page does not change.
I wrote this code:
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
document.body.style.display="none";
var url = document.referrer;
var domainname;
var referal_code = getCookie("protect_faq_pages");
console.log(url);
if(url){
var anchor = document.createElement("a");
anchor.href = url;
domainname = anchor.host;
console.log(domainname);
if(domainname == "softwareservicetech.com"){
var cookieString = "protect_faq_pages=cWs#fgf$a1fD#FsC-)";
document.cookie = cookieString;
}
}else if(!(referal_code == "cWs#fgf$a1fD#FsC-)")){
document.getElementById("page").innerHTML="<p>Sorry you do not have permission to view the content</p>"
}
console.log(referal_code);
document.body.style.display="block";
this site can be accessed itself:
https://health-unity.com/
you can find out the page below is restriced on the view :
https://health-unity.com/help-centre/videos/
and also these pages too:
https://health-unity.com/help-centre/videos/video-number-2/
https://health-unity.com/help-centre/videos/video-number-1/
but when click on the link on below site (link to health-unity-videos):
https://softwareservicetech.com/testpage/
the archive page will be accessible after that. user can go to the pages below directly:
https://health-unity.com/help-centre/videos/video-number-2/
https://health-unity.com/help-centre/videos/video-number-1/
these were restricted before and now can be accessed by a cookie that is set.
but the problem is that page source still exist and did not changed by javascript code and user can view the page source. also I want that the cookie value should be hidden. because of these two problem I think javascript is not a good idea.
please share with me if there is way with javascript, php, or editing functions.php or .htaccess file to achieve this.
thank you for your response in advance
You can use $_SERVER['HTTP_REFERER'] in functions.php
For example:
<?php
add_action('init','check_referrer');
function check_referrer(){
if( str_contain($_SERVER['HTTP_REFERER'], 'https://example-domain.com/'){
// do somthing
}else{
// do somthing else
}
}
?>
I have an email sender linked to a google sheets file as follows:
function sendEmail(form) {
const sSheet = SpreadsheetApp.getActiveSpreadsheet();
const file = DriveApp.getFileById(sSheet.getId());
const documentUrl = file.getUrl();
var toEmail = form.toAddress;
var ccEmail = form.ccAddress;
var subject = form.subject;
var message = form.message;
const folderId = "";
const ssId = sSheet.getId();
const returnFlag= 'blob';
if (form.process == "sendHotelRegistration"){
var fileName = "Hotel Registration Form";
var sheetId = sSheet.getSheetByName("Hotel Registration form").getSheetId();
var sheet= sSheet.getSheetByName("Hotel Registration form");
sheet.showSheet();
} else if (form.process == "updateRegistry"){
var fileName = "Hotel Contract Document";
var sheetId = "All";
}
var pdfFile = createPDF(folderId, ssId, fileName, sheetId, returnFlag);
MailApp.sendEmail({
to:toEmail,
cc:ccEmail,
subject:subject,
body:message,
attachments:[pdfFile]
});
}
I have 2 issues:
1- I want to add a signature including a logo to the email. So I need the company name in bold and the logo. I cannot work out how to insert an image or to have formatted text. I have read through a lot of posts and the following google documentation: https://developers.google.com/apps-script/reference/mail/mail-app
And I have tried to implement this in my code but I cannot get it to work.
Secondly, I have a variable set in my email body which retrieves a value from my google sheet document as follows:
html.contractorName = data.contractorName.toLowerCase();
However, I don't actually want lower case, I want title / proper case. I cannot though work out how to implement this, particularly bearing in mind that the contractor name may be two, three, four names long.
Thanks
I have a similar sheetsEmail document. The logo problem took me a long time to solve, I recently found a semi-convenient solution from the following source.
The relevant code can take your personal signature as a string, and with htmlBody it can include images, all the desired formatting and what not.
var signature = Gmail.Users.Settings.SendAs.list("me").sendAs.filter(function(account){if(account.isDefault){return true}})[0].signature;
From your comment on another reply, you are correct that it causes some problems with your regular body. My solution was to include html tags around it as well, and concatenate the two strings. So, for example, my original body is stored in the var bod:
var body1 = "<p>"+bod+"</p>"+signature;
You could fool around with different tags to get the desired format.
To solve your spaces and new lines issue, you could search your original body string and replace line break \n with the html br> tag, but I can't help you on the specifics of that!
You can attach your logo and name to the message and send email in HTML format.
Something like this
message += "<BR><BR>" + name + "<BR><BR> <inline logo image>";
You can use htmlBody parameter(to add name logo to email body) and inlineImages options (to attach logo).
Check this for full reference.
https://developers.google.com/apps-script/reference/mail/mail-app#sendemailmessage
Please read MailApp.sendEmail() documentation here :
// This code fetches the Google and YouTube logos, inlines them in an email
// and sends the email
function inlineImage() {
var googleLogoUrl = "http://www.google.com/intl/en_com/images/srpr/logo3w.png";
var youtubeLogoUrl =
"https://developers.google.com/youtube/images/YouTube_logo_standard_white.png";
var googleLogoBlob = UrlFetchApp
.fetch(googleLogoUrl)
.getBlob()
.setName("googleLogoBlob");
var youtubeLogoBlob = UrlFetchApp
.fetch(youtubeLogoUrl)
.getBlob()
.setName("youtubeLogoBlob");
MailApp.sendEmail({
to: "recipient#example.com",
subject: "Logos",
htmlBody: "inline Google Logo<img src='cid:googleLogo'> images! <br>" +
"inline YouTube Logo <img src='cid:youtubeLogo'>",
inlineImages:
{
googleLogo: googleLogoBlob,
youtubeLogo: youtubeLogoBlob
}
});
}
Get the Blob of your logo and assign it to inlineImages property. Then you can include it in your HTML body.
Use HTML to format the body according to your needs and assign it to htmlBody property.
About the contractor name, try with this prototype function:
html.contractorName = data.contractorName.toProperCase();
String.prototype.toProperCase = function () {
return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
};
It will capitalize each word in the string so john dOe becomes John Doe.
You're seeing the Reference error because you don't have the Gmail API enabled. You can enable the API in the developer console. You will then have to enable it for the individual script you're working on. Clicking Resources > Advanced Google services then flip the on-switch next to Gmail API
I'm building a web app using HTML, CSS and JavaScript and using Google Spreadsheet as a database. I'm planning to use PhoneGap to turn my web app into a real app.
I was able to read from my Google Sheet, using the Google Visualization API, now I'm working about the writing options: I used a function set with Google Apps Script, inside the Google Spreadsheet and it works correctly.
This is how my app works and what I need:
I query my first Google Spreadsheet (Database)
If I cannot find what I need, I can make a request
I send the request: the action of the form send my data to the Google Apps Script code
The GAS writes my data in a second Google Spreadsheet (Register)
The GAS should send me back to my page
The page sends a feedback on screen
As you can understand by the bold point, I'm not able to go back to my webpages... I don't know if there's any method or function to do this. The only thing I found was using ContentServiceto make the page "write another form and send it using JavaScript", but I don't think is the best solution...
I'll post my code down here... hoping someone can help me
function doPost(e){
var sheet = SpreadsheetApp.openById("myID").getSheetByName('SheetName');
var column = 1;
var colArray = sheet.getRange(2, column, sheet.getLastRow()).getValues();
var maxi = Math.max.apply(Math, colArray);
var id = maxi+1;
var name = e.parameter['name'];
var surname = e.parameter['surname'];
var serial = e.parameter['serial'];
var eMail = e.parameter['mail'];
var text = e.parameter['text'];
var area = e.parameter['area'];
var date = new Date();
var ans = ""
var flag = "Work In Progress";
var vals = [id, date, name, surname, serial, eMail, area, text, ans, flag];
var sheetObj = sheet.appendRow(vals);
// return ContentService.createTextOutput(someOutput);
On the return line I should go back to my web app/app but I can't find a way to do it. Someone can help me or give me some advice?
Thanks a lot for your help!
S.
This is the solution to your problem.
Instead of using return ContentService.createTextOutput(someOutput);
use HtmlService to return to your form
return HtmlService.createHtmlOutputFromFile('redirect').setSandboxMode(HtmlService.SandboxMode.IFRAME);
And your HTML file should look like this,
Update: redirect.html should be in the same project as that of your app script file.
redirect.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<title>This Is A Sample Title</title>
<script>
function test()
{
window.location.href = "www.hostname.com";
}
</script>
</head>
<body onload="test()">
Login
</body>
</html>
See if this works for you.
I want to create a Bookmarklet which will load one link out of a list of ten links, order doesn't matter, but weight-age does.
I tried http://www.htmlbasix.com/textrotator.shtml but it's for rotating a link on a webpage, how to make a Bookmarklet which will open a random URL from the list? Kind of URL rotator script within a bookmark.
Any efficient way to do that?
Thanks in advance.
You can't setup bookmarklet to run automatically. Consider writing browser extension or just use curl.
Not automatically.
Then it varies.
First, if you're 100% that pages don't redirect you anywhere you can try to use window.location inside you bookmarklet in next way:
var next = urls.indexOf(window.location.href) + 1;
next = next < urls.length ? next : 0;
window.location = urls[next];
If one of pages redirects or messes with url then you can use localStorage on your own domain and postMessage to store any data between bookmarklet calls.
I have found the solution after few tries
javascript: (function randomlinks() {
var myrandom = Math.round(Math.random() * 9);
var links = new Array();
links[0] = "http://www.javascriptkit.com";
links[1] = "http://www.dynamicdrive.com";
links[2] = "http://www.cssdrive.com";
links[3] = "http://www.codingforums.com";
links[4] = "http://www.news.com";
links[5] = "http://www.gamespot.com";
links[6] = "http://www.msnbc.com";
links[7] = "http://www.cnn.com";
links[8] = "http://news.bbc.co.uk";
links[9] = "http://www.news.com.au";
window.location = links[myrandom];
})()