Bookmarklet approach - security

I am trying to write a bookmarklet that will bookmark the current page and save the link to the current page in a backend service. When I click this bookmarklet, I want this bookmarklet to show up as a small popup on the top right in browser tab (attach iframe to existing page). This popup will have options to bookmark current page. Also, there will be options search my bookmarks, tag, etc in this popup.
So far, I have not seen any such bookmarklets (from delicioius, pinboard,etc). Although there are bookmarklets to post links to various services, they don't let you search, see the existing list of bookmarks within in the same popup. User is forced to go to the bookmarking site in a new tab to search, etc.
I am wondering is there a reason why bookmarklets (popup within existing page) like this are not done? Are there any security reasons for this? Or will be be blocked by adblockers?

Have a look at these bookmarklets http://googlesystem.blogspot.com/2007/07/useful-google-bookmarklets.html
javascript: (function() {
var a = window,
b = document,
c = encodeURIComponent,
d = a.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + c(b.location) + "&title=" + c(b.title), "bkmk_popup", "left=" + ((a.screenX || a.screenLeft) + 10) + ",top=" + ((a.screenY || a.screenTop) + 10) + ",height=420px,width=550px,resizable=1,alwaysRaised=1");
a.setTimeout(function() {
d.focus()
},
300)
})();

Related

Cannot set notebook page in fuction with gtk in nodejs

I have notebook pages setup like tabs in a browser. You click the "+" tab and it creates a new page and moves the "+" tab to the end. That all works except I'm trying to change to the page that was created. Attempting to use "setCurrentPage" doesn't do anything. No errors are thrown and it stays on the current tab completely ignoring the command.
It doesn't matter what index number I put in the command. Still nothing happends. I thought maybe it has something to do with the switch-page signal but all the other commands work.
edit: I should add that it doesn't work outside the function either.
notebook.on('switch-page', AddTab)
function AddTab(selff, page, index) {
b = notebook.pageNum(newtab)
a = (notebook.getCurrentPage() + 1)
if ( b == a) {
TabPage()
notebook.reorderChild(newtab, -1)
//notebook.setCurrentPage(page)
win.showAll()
notebook.setCurrentPage(page)
}
}

Code not saving when trying to wrap promoted tiles in SharePoint Online

Apologies for another question re this, but I've tried so hard to get this working (I'm fairly new to SharePoint, don't have extensive coding knowledge, but know HTML and generally alright at trouble shooting).
We are using SharePoint online and we have SharePoint Tiles. We have recently added a few more tiles and it's obviously not wrapping these tiles, thus having to scroll right to access some.
I have found the code for wrapping the tiles here and when editing the page source, it appears to be working... until I save it. The code I put in is stripped out when I next go to the content editor.
I've read a few pages on it and have tried things such as the content editor web part, but for the life of me cannot get it to work.
If anyone would know if there's a step to step guide to ensure wrapped tiles are saved, I may be able to get it to work.
Any help is greatly appreciated.
If it changes anything, we use SharePoint online that is part of our Office 365 account.
Add the following code into script editor web part in the page.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Update this value to the number of links you want to show per row
var numberOfLinksPerRow = 6;
// local variables
var pre = "<tr><td><div class='ms-promlink-body' id='promlink_row_";
var post = "'></div></td></tr>";
var numberOfLinksInCurrentRow = numberOfLinksPerRow;
var currentRow = 1
// find the number of promoted links we're displaying
var numberOfPromotedLinks = $('.ms-promlink-body > .ms-tileview-tile-root').length;
// if we have more links then we want in a row, let's continue
if (numberOfPromotedLinks > numberOfLinksPerRow) {
// we don't need the header anymore, no cycling through links
$('.ms-promlink-root > .ms-promlink-header').empty();
// let's iterate through all the links after the maximum displayed link
for (i = numberOfLinksPerRow + 1; i <= numberOfPromotedLinks; i++) {
// if we're reached the maximum number of links to show per row, add a new row
// this happens the first time, with the values set initially
if (numberOfLinksInCurrentRow == numberOfLinksPerRow) {
// i just want the 2nd row to
currentRow++;
// create a new row of links
$('.ms-promlink-root > table > tbody:last').append(pre + currentRow + post);
// reset the number of links for the current row
numberOfLinksInCurrentRow = 0;
}
// move the Nth (numberOfLinksPerRow + 1) div to the current table row
$('#promlink_row_' + currentRow).append($('.ms-promlink-body > .ms-tileview-tile-root:eq(' + (numberOfLinksPerRow) + ')'));
// increment the number of links in the current row
numberOfLinksInCurrentRow++;
}
}
});
</script>
We can also use CSS style below in script editor web part in the page to achieve it.
<style>
.ms-promlink-body {
width: 960px;
}
</style>

How to click "Next" button until it no longer exists - Python, Selenium, Requests

I am scraping data from a webpage that is paginated, and once I finish scraping one page, I need to click the next button and continue scraping the next page. I then need to stop once I have scraped all of the pages and a next button no longer exists. Below contains the html around the "Next" button that I need to click.
<tr align="center">
<td colspan="8" bgcolor="#FFFFFF">
<br>
<span class="paging">
<b> -- Page 1 of 3 -- </b>
</span>
<p>
<span class="paging">
<a href="page=100155&by=state&state=AL&pagenum=2"> .
<b>Next -></b>
</a>
</span>
<span class="paging">
Last ->>
</span>
</p>
</td>
</tr>
I have tried selecting on class and on link text, and both have not worked for me in my current attempts.
2 examples of my code:
while True:
try:
link = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Next ->"))).click()
except TimeoutException:
break
while True:
try:
link = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "paging"))).click()
except TimeoutException:
break
All of the solutions I have found online have not worked, and have primarily ended with the following error:
ElementClickInterceptedException: Message: element click
intercepted: Element <a href="?
page=100155&by=state&state=AL&pagenum=2">...</a> is not
clickable at point (119, 840). Other element would receive the
click: <body class="custom-background hfeed" style="position:
relative; min-height: 100%; top: 0px;">...</body>
(Session info: chrome=76.0.3809.132)
If the remainder of the error code would be helpful to review, please let me know and I will update the post with this error.
I have looked at the following resources, all to no avail:
Python Selenium clicking next button until the end
python - How to click "next" in Selenium until it's no longer available?
Python Selenium Click Next Button
Python Selenium clicking next button until the end
Selenium clicking next button programmatically until the last page
How can I make Selenium click on the "Next" button until it is no longer possible?
Could anyone provide suggestions on how I can select the "Next" button (if it exists) and go to the next page with this set of HTML? Please let me know if you need any further clarification on the request.
We can approach this problem through the solution using two major libraries - selenium and requests.
Approach - Scrape the page for page number and next page link every time
Using Selenium (If the site is Dynamic)
We can check if the page we are on is the last page or not, and if it is not the last page, we can check for the next button (assuming the website follows the same html structure for paging in all pages)
stop = False
driver.get(url)
while not stop:
paging_elements = driver.find_elements_by_class_name("paging")
page_numbers = paging_elements[0].text.strip(" -- ").split("of")
## Getting the current page number and the final page number
final = int(page_numbers[1].strip())
current = int(page_numbers[0].split("Page")[-1].strip())
if current==final:
stop=True
else:
next_page_link = paging_elements[-2].find_element_by_name("a").get_attribute('href')
driver.get(next_page_link)
time.sleep(5) # This gap can be changed as per the load time of the page
Using Requests and BS4 (If the site is static)
import requests
r = requests.get(url)
stop = False
while not stop:
soup = BeautifulSoup(r.text, 'html.parser')
paging_elements = soup.find_all('span', attrs={'class': "paging"})
page_numbers = paging_elements[0].text.strip(" -- ").split("of")
## Getting the current page number and the final page number
final = int(page_numbers[1].strip())
current = int(page_numbers[0].split("Page")[-1].strip())
if current==final:
stop=True
else:
next_page_link = paging_elements[-2].find("a").get('href')
r = request.get(next_page_link)
Alternative approaches
One method is using the URL of the website itself instead of the button-clicking process as the button click is intercepted in this case.
Most web pages have a page attribute added to their URL (visible for pages >=2). So, a paginated website might have URLs such as:
www.targetwebsite.com/category?page_num=1
www.targetwebsite.com/category?page_num=2
www.targetwebsite.com/category?page_num=3
and so on.
In such cases, one can simply iterate over the page numbers until the final page number (as originally out in the proposed answer). This approach eliminates the breakage possibility of the target website changing CSS layout/style.
Furthermore, there might be a requirement to create the next_page_link by appending the base URL as done for next_url in the other question (line 40-41):
next_url = next_link.find("a").get("href")
r = session.get("https://reverb.com/marketplace" + next_url)
I hope this helps!
It sounds like you're asking two different questions here:
How to click Next button until it no longer exists
How to click Next button with Javascript.
Here's a solution to #2 -- Javascript clicking:
public static void ExecuteJavaScriptClickButton(this IWebDriver driver, IWebElement element)
{
((IJavaScriptExecutor) driver).ExecuteScript("arguments[0].click();", element);
}
In the above code, you have to cast your WebDriver instance as IJavascriptExecutor, which allows you to run JS code through Selenium. The parameter element is the element you wish to click -- in this case, the Next button.
Based on your code sample, your Javascript click may look something like this:
var nextButton = driver.findElement(By.LINK_TEXT, "Next ->"));
driver.ExecuteJavascriptClickButton(nextButton);
Now, moving onto your other issue -- clicking until the button is no longer visible. I would implement this in a while loop that breaks whenever the Next button no longer exists. I also recommend implementing a function that can check the presence of the Next button, and ignore the ElementNotFound or NoSuchElement exception in case the button does not exist, to avoid breaking your test. Here's a sample that includes an ElementExists implementation:
public bool ElementExists(this IWebDriver driver, By by)
{
// attempt to find the element -- return true if we find it
try
{
return driver.findElements(by).Count > 0;
}
// catch exception where we did not find the element -- return false
catch (Exception e)
{
return false;
}
}
public void ClickNextUntilInvisible()
{
while (driver.ElementExists(By.LINK_TEXT, "Next ->"))
{
// find next button inside while loop so it does not go stale
var nextButton = driver.findElement(By.LINK_TEXT, "Next ->"));
// click next button using javascript
driver.ExecuteJavascriptClickButton(nextButton);
}
}
This while loop checks for the presence of the Next button with each iteration. If the button does not exist, the loop breaks. Inside the loop, we call driver.findElement with each successive click, so that we do not get a StaleElementReferenceException.
Hope this helps.

dynamically adding PXTabItem from codebehind

Trying to add a new tab items from the page cs file in the Page_Init method which contains a PXSmartPanel in Iframe mode.
Initially I just created the blank tab
for (int i=0;i<3;i++)
{
PXTabItem tabItem = new PXTabItem();
tabItem.Key = "myKey"
tabItem.Text = "myTab" + i;
tabItem.Visible = true;
this.tab.Items.Add(tabItem);
PXSmartPanel smartPanel = new PXSmartPanel();
smartPanel.RenderIFrame = true;
smartPanel.InnerPageUrl = "thispage" + i;
..... {other smartpanel properties}
tabitem.TemplateContainer.Controls.Add(smartPanel);
}
This does create the tabs on my page and works/looks correctly in Chrome however in Firefox, the style of the iframe rendered is always 150px regardless of the style set in the smartPanel above.
Tried adding the following
smartPanel.height = new Unit(100, UnitType.Percentage);
smartPanel.Style["height"] = "100%";
Tried even forcing a specific size of say 600px.
As a secondary test, I added directly to my page the tab items, smart panels and those render correctly in both Chrome and Firefox.
I also attempted to create a "dummy" / "template" and use the tabitem.CopyFrom() method to set it up. This also renders correctly in chrome but not firefox.
Has anyone added tab items directly from the code behind file and have any hints on what property I am missing here?

SharePoint Hiding fields in newform, dispform, editform

I have a task here when I need some assistance. what I am trying to accomplish is the follow..
Hide some fields on the newform, editform and dispform with in SharePoint (2013)
The field I am trying to hide is ONLY the input/textbox field not the whole column/heading associated with it. Basically I have a form with a heading and an associated textbox(single line of text) next to it, what I would like to do is hide the textbox only.
I have used the F12 IE tools to select the text box to which displays the following souce code:
<input title="Travel" class="ms-long ms-spellcheck-true" id="Travel_f6801fb9-c4ff-4109-acb9-f7dd63c1d98a_$TextField" type="text" maxlength="255" value="">
(the textbox is associated with my "Travel" column)
Now when I use the F12 tools while selecting this, I added some css(from that I can tell) under the "inline Style" top heading which was "display=none" and bingo it works!.
Now what I cant do here is add this to the forms permanently. I have tried to google this by adding a Content web part to the form and try some CSS/Java script but I simply do not have the skills in this area.. does this make sense?
examples:
any help would be great
Cheers!
In SharePoint 2013 was introduced Client Side Rendering (aka CSR) which is used for rendering list views, list forms and search results. For a more details follow SharePoint 2013 Client Side Rendering: List Forms article.
The following JavaScript template demonstrates how to hide field controls in List Form pages:
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: hideFieldControls
});
});
function getFieldControlId(field){
return field.Name + '_' + field.Id + '_$' + field.Type + 'Field';
}
function hideFieldControl(field){
var fieldControlId = getFieldControlId(field);
var fieldControl = document.getElementById(fieldControlId);
fieldControl.style.display = "none";
}
function hideFieldControls(ctx){
var fieldNamesToHide = ['JobTitle','WorkPhone']; //<- set field names to hide here
if(fieldNamesToHide.indexOf(ctx.ListSchema.Field[0].Name) > -1) {
hideFieldControl(ctx.ListSchema.Field[0]);
}
}
How to apply changes
Open List Form page in edit mode
Add Script Editor web part on the page
Insert the specified JavaScript template by enclosing it using
script tag Note: specify field names to hide via fieldNamesToHide variable
Save page
Results
Pic 1. Original New Form page
Pic. 2 Customized New Form (field controls for Job Title and Business Phone are hidden)

Resources