How to get event ID from Google Calendar page with JavaScript? - google-chrome-extension

I am creating a Google Chrome extension for Google calendar. I want to get the ID of an event when user visits the event edit page.
How can I get the event ID from the plugin's javascript code so that I can fire Calendar api v3.0 with that ID.
Adding extra info:
Google Calendar API calendar id and event id
The comment by #krishna actualy shows how to get the event ID and it works. But how to get the event ID in https://www.google.com/calendar/ URL not in the URL(https://www.google.com/calendar/render?gsessionid=OK&eventdeb=1) as told by Krishna.

It's in the data-eid attribute that you partially covered in black in the screenshot. It is encoded along with other things as base64 (or base64url).
The following code should decode, extract, and print the event ID (assuming jQuery was loaded):
var encoded = $("div.ep[data-eid]").attr("data-eid");
if (encoded !== undefined) {
var decoded = atob(encoded);
console.log("Current event ID: " + decoded.split(" ")[0]);
}
prints something like:
Current event ID: 75v3thapnpd234ocglgk625frc

Related

Is it possible to trigger an event if a puppeteer browser is on a certain URL or has a certain element on the webpage?

Is it possible to trigger an event via puppeteer if the browser is on a certain URL or has a certain element on the webpage?
I have a browser open, user interacts with the page and do whatever they want until they are on a certain URL. Is this possible to trigger an event like this?
Yes, this is possible. Both options you are describing are viable. The easier way would be to check the requests that are happening.
Check for requests/URLs
Here is a code sample which checks what requests are happening by listing on the request event. Keep in mind that the request could be happening anywhere on the page (in an iframe for example). Depending on your use case, you might therefore also want to check if the request happened inside the main page (by using page.url()).
page.on('request', request => {
const url = request.url();
if (url === '...') {
// trigger event
}
});
Check for an element
If you want to check if a specific element is present on the page, you can wait for the domcontentloaded event and then check if the element is present:
page.on('domcontentloaded', () => {
const element = page.$('#element-selector');
if (element) {
// element is present, trigger event
}
});
Keep in mind that, this will only check for it once. To continuously check if the element is present, you can use a MutationObserver (see an example for that here).

Alert in view record for Netsuite

I have been trying to get a alert in Netsuite for view mode but can't get it for customer record.
Though when I tried to get the alert for the edit record then I got it but I want it for view.
I tried client script, user event script and also workflow. But all support only for edit. Can I get the alert by any means for the view record option.
Thanks
Gladiator
One workaround that I've done is to add a custom field of type 'Inline HTML' to the customer form. Then during the beforeLoad event you can check if type == 'view' and update the custom field's value with the HTML that is needed to display the alert.
Basically form.setScript used to work with SS1 but there was no (not hacked) API access to Netsuite's alerts
SS2.0 gives nice access to the alert system but it doesn't load in view mode unless you take a supported action (clicking a button)
See this answer for a sample with SS2 that loads your script and shows an integrated alert.
SS2.0 Display Message on Record
Thanks Mike, Michoel and Bknights.
Here is the solution to the problem.
Create an inline html field on the customer form.
Since the field does not store value nlapiSetFieldValue for before load function works absolutely fine.
Below is the snippet of the working code.
function before_load(type)
{
if (type == 'view')
{
var pass_value = "<html><body><script type='text/javascript'>window.alert('Hello World!!!')</script></body></html>";
nlapiSetFieldValue("custentity25", pass_value); //custentity25 is the id of Inline HTML field we created
}
}
Note : The "" used should be different then the one used in the HTML code which is ''. If same are used then there will be an error.
You need to use a User Event Script, and in the before load event, set a Client Script via form.setScript(). In your "injected" Client Script, you can display the alert.

Netsuite: How to insert an iframe on post call

I have written a suitelet which has two parts - GET and POST.
In GET method I have a dropdown and a submit button.
In POST method, I have 5 text fields which display the data based on value fetched from dropdown in GET.
I want to call an iframe on submit button click. iframe will show POST method logic. In short, I don't want to navigate to new page on submit, but to make the whole thing work on a single page.
MY CODE
function init(request, response)
{
if(request.getMethod() == 'GET')
{
//... some code for dropdown and submit
//code for iframe
var context = nlapiGetContext();
var url = 'https://**url-of-post-method-results**.com';
var title = context.getSetting('SCRIPT', 'custscript_suitelet_title')
var content = '<iframe width=960px height=100% style="height:640px;" src=' + url + '></iframe>'
var newField = form.addField ('content', 'inlinehtml', title);
form.addField('extra', 'inlinehtml', '')
form.setTitle (title);
newField.setLayoutType('outsidebelow');
newField.setDefaultValue (content);
form.addSubmitButton('Submit');
response.writePage(form);
}
}
I referred to Marty Zigman's tutorial on embedding iframe. But I'. confused where to embed the iframe, in GET or POST?
To the best of my knowledge, NetSuite has no built in way via their API to avoid a page refresh in a case like this. Clicking the submit button, will by default, submit the form via a post method synchronously. You need to interrupt the click() event method via jQuery on NetSuite's default form submit button using client side code. You would then send the post yourself using jQuery, and on a response, show the information you would like, again via jQuery, by updating the iframe src url.
I apologize I do not have currently have access to an account to be able to give you the appropriate JavaScript. I would be cautious of breakage though since you will need to hack into the NetSuite UI a bit to make this work.

Save record embedded in iframe

Scenario
CRM2011, rollup 13
Account form with iframe, that displays contact form. Requirement is that when user press "save" button on account form, contact in iframe should be also saved.
OnSave event code
var iframeXrmPage = Xrm.Page.getControl("IFRAME_contact").getObject().contentWindow.Xrm.Page;
iframeXrmPage.data.entity.save(); //error: Unable to get property 'entity' of undefined or null reference
I can get Xrm object of iframe, but it has data and ui members set to null.
Is there any way to call save() in iframe using Xrm.Page? Are there any alternatives?
Use below code:
var iframeXrmPage = Xrm.Page.getControl("IFRAME_contact").getObject().contentWindow.contentIFrame.Xrm.Page;

Need to reload content script for chrome extension on facebook

I created a Chrome extension that adds links to items (things your friends share with you) on your facebook feed. Facebook loads about 10 or 20 items on the feed on page load, and then the rest are loaded via ajax when you scroll down.
I managed to get my content script to work for the first items, but not for the rest. I've read everything i could find, and it seems that I have to reload my content script.
How can i do that considering that the URL does not change?
You can use document.addEventListener with the DOMNodeInserted event to listen for new items getting rendered in the feed. The callback will have to check each node insertion to see if it is a feed item or not. Something like the following should work.
function nodeInsertedCallback(event) { console.log(event); });
document.addEventListener('DOMNodeInserted', nodeInsertedCallback);
Well, you can hang some time driven listener that runs every XX seconds, to verify if there's new items to work with.
Unfortunately there's no event you can hang from, fired when the page's code do some Ajax.
May be you can figure out what evet you can han from to detect the user has reached the end of the loaded item's list, knowing that de page's code will do some Ajax to retrieve more items. Then you start you time driven listenter.

Resources