From the title this may sound like a duplicate question. But what I am asking for is help writing a Greasemonkey script that takes all images containing the word "thumbnails" in the src url, replaces "thumbnails" with "images" but then putting the new url into the href (target) url.
What I have so far is:
for(var iImage=0;iImage<document.images.length;iImage++){
var imageUrl = document.images[iImage].src;
if (imageUrl.indexOf("thumbnails") != -1) {
imageUrl = imageUrl.replace("thumbnails","images")
document.images[iImage].href = imageUrl;
}
}
Any help would be appreciated.
img tags cant have href, however you can append them into an anchor tag with href attribute:
for(var iImage=0;iImage<document.images.length;iImage++){
var imageUrl = document.images[iImage].src;
if (imageUrl.indexOf("thumbnails") != -1) {
imageUrl = imageUrl.replace("thumbnails","images");
document.images[iImage].outerHTML = '<a href ="' +
+ imageUrl + '" >'
+ document.images[iImage].outerHTML + '</a>';
}
}
Psuedo-code:
var thumblinks=new Array();
for(x=0;x<links.length;x++){
if(links[x].href.test('thumbnails'))thumblinks[thunblinks.length]=links[x];
}
for(x=0;x<thumblinks.length;x++){
thumblinks[x].href=thumblinks[x].firstChild.src;
}
Does this work?
Related
I have form for upload file and i want to upload thumbnail for the file in the same form I am doing that with this part of code :
var basePath2 = Path.Combine(Directory.GetCurrentDirectory() + "\\Thumbnails\\");
bool basePathExists2 = System.IO.Directory.Exists(basePath2);
if (!basePathExists2)
Directory.CreateDirectory(basePath2);
var thumbnailPath = Path.Combine(basePath2, Thumbnail.FileName);
if (!System.IO.File.Exists(thumbnailPath))
{
using (var stream = new FileStream(thumbnailPath, FileMode.Create))
{
await Thumbnail.CopyToAsync(stream);
}
}
I am saving this model to the database:
var fileModel = new FileUploadViewModel
{
Year = createdOn,
PublishedOn = model.PublishedOn,
FileType = File.ContentType,
Extension = extension,
Name = model.Name,
Description = model.Description,
FilePath = filePath,
Author = model.Author,
ThumbnailPath = thumbnailPath,
};
When I want to show the thumbnail in a view, it doesn't work but in src I have the right path, as you can see in this screenshot:
Screenshot with Source of image
In controller :
string uniqueThumbName = null;
if (Thumbnail != null)
{
string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Thumbnails");
uniqueThumbName=Guid.NewGuid().ToString() + "_" + Thumbnail.FileName;
string filePath2 = Path.Combine(uploadsFolder, uniqueThumbName);
Thumbnail.CopyTo(new FileStream(filePath2, FileMode.Create));
}
var fileModel = new FileUploadViewModel
{
ThumbnailPath=uniqueThumbName,
};
In View :
var thumbPath = "~/Thumbnails/" + file.ThumbnailPath;
<img style="width:80px;height:80px;" src="#thumbPath" asp-append-version="true" />
I've been having trouble finding the proper or accurate Xpath for google sheets ImportXML.
Article in question:
https://www.digitaltrends.com/news/this-is-what-a-birthday-party-on-the-iss-looks-like/
Result i'm looking for:
'post_name': 'this-is-what-a-birthday-party-on-the-iss-looks-like'
Using the "copy full XPath feature in Chrome Inspect feature, i'm getting:
/html/head/script[43]/text()
Which does not work with Google Sheet's ImportXML feature. Can someone guide me through how will i be able to pull this section of the site?
EDIT: I'm trying to retrieve anything within these parameters such as "post name, post title, post id." [View Source1
The page is built in javascript on the client side, not the server side. It is therefore impossible to retrieve information with the IMPORTXML function. You need to read what is included in the script ...
function extract(){
var url='https://www.digitaltrends.com/news/this-is-what-a-birthday-party-on-the-iss-looks-like/'
var source = UrlFetchApp.fetch(url).getContentText()
var data = source.split('<script>')
//Logger.log(data[3])
info = "'post_name" + data[3].split('post_name')[1].split(',')[0]
Logger.log(info)
}
Now if you want to retrieve all the information contained in the JSON
function extract(){
var url='https://www.digitaltrends.com/news/this-is-what-a-birthday-party-on-the-iss-looks-like/'
var source = UrlFetchApp.fetch(url).getContentText()
var data = source.split('<script>')
//Logger.log(data[3])
info = data[3].replace(/(\t)/gm,"").replace(/(\n)/gm,"").replace(/(')/gm,"\"").replace(/(: )/gm,":")
info = info.split('({')[1].split(',});}')[0]
//Logger.log(info)
var myData = JSON.parse('{' + info + '}')
getPairs(eval(myData),'myData')
}
function getPairs(obj,id) {
const regex = new RegExp('[^0-9]+');
const fullPath = true
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
for (let p in obj) {
var newid = (regex.test(p)) ? id + '.' + p : id + '[' + p + ']';
if (obj[p]!=null){
if (typeof obj[p] != 'object' && typeof obj[p] != 'function'){
sheet.appendRow([fullPath?newid:p, obj[p]]);
}
if (typeof obj[p] == 'object') {
getPairs( obj[p], newid );
}
}
}
}
Here I have tis function that is querying data and returning it to me and im putting that data in to html elements to make a post.my if statement at the bottom is where im having a bit of problem i trying to only apply my comment window once to the new clones once they have been pushed over to the new div called story board, i believe im telling my if statement that if the class already exists in that new clone then do nothing else apply it there.. to seee what i am talking about...here is my test domain...http://subdomain.jason-c.com/
sign in is "kio" pass is the same and when you hit publish on the stories, everytime a nw one hits it will apply comment box to a post in the storyboard window that already has a comment text area. what am i doing wrong.
function publishWindowHandler(){
var query = new Parse.Query('Post');
console.log(currentUser);
query.equalTo("User", currentUser);
query.include("User");
query.descending("createdAt")
console.log(user.get('username'));
query.find({
success:function(results){
document.getElementById("publishCenter").textContent = "";
for(var i =0; i < results.length; i++){
var userPost = results[i];
//console.log(userPost.get("User") + " / " + userPost.get("Author") + " / " + userPost.get("Story") + " / " + userPost.get("objectId"));
var authorTitle = document.createElement("p");
var newPost = document.createElement("P");
var title = document.createElement("P");
var userLabel = document.createElement("p");
var postId = userPost.id;
var postBtn = document.createElement("INPUT");
postBtn.className ="publishBtn";
postBtn.id ="publishBtn";
postBtn.setAttribute("Type", "button");
postBtn.setAttribute("value", "Publish");
title.textContent = "Story: " + userPost.get("Title");
authorTitle.textContent = "Author: " + userPost.get("Author");
newPost.textContent = userPost.get("Story");
userLabel.textContent = "Published by: " +userPost.get("User").get ("username");
var postWrapper = document.createElement("DIV");
postWrapper.className = "postWrapper";
postWrapper.id = postId;
document.getElementById("publishCenter").appendChild(postWrapper);
postWrapper.appendChild(title);
postWrapper.appendChild(authorTitle);
postWrapper.appendChild(newPost);
postWrapper.appendChild(userLabel);
postWrapper.appendChild(postBtn);
postBtn.addEventListener("click", publicViewHandler);
function publicViewHandler(){
$(this).parent(".postWrapper").clone().appendTo(".storyBoard");
function testWindow(){
if($(publicBoard).children().hasClass(".commentWindow")){
}
else
{
$(".storyBoard").children().append(commentWindow);
}
}
testWindow();
}
}
}
})
}
According to the documentation, jquery hasClass doesn't need '.' prefixing the passed in class name.
https://api.jquery.com/hasclass/
Try removing that and see if that get's you anywhere.
Also, where is the variable commentWindow defined? Is it global?
var myClone = $(this).parent().clone(true);
myClone.appendTo(".storyBoard");
console.log(publicBoard);
console.log("hello",$(this));
console.log($(publicBoard).find('.postWrapper').find("commentWindow"));
myClone.append($(commentWindow).clone());
this is what i ended up doing to solve my issue took me a while and a little help from a friend.
Is there a way to modify the code of the Joomla's search component so it can display even the article's image?
I have made a simple code that can search the image or youtube video in the article's text and return the media including the required tags as a string, but where do I put it?
// SEARCH IMAGE OR VIDEO
$hasImage = 0;
$hasVideo = 0;
$articleMedia = '';
$articleText = $text;
// has image?
preg_match_all('/<\s?img[^>]+\>/i', $articleText, $matches);
if(isset($matches['0']['0']))
{
$articleMedia = $matches['0']['0'] ;
$hasImage = 1;
}
// no image? maybe video
if ($hasImage == 0) {
preg_match_all('/(http:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]+))/i', $articleText, $matches);
if(isset($matches['0']['0']))
{
$articleMediaID = $matches['2']['0'] ;
$articleMedia = "//www.youtube.com/embed/" . $articleMediaID;
$hasVideo = 1;
} else {
preg_match_all('/(http:\/\/youtu.be\/([a-zA-Z0-9_-]+))/i', $articleText, $matches1);
if( isset($matches1['0']['0']) ){
$articleMediaID = $matches1['2']['0'] ;
$articleMedia = "//www.youtube.com/embed/" . $articleMediaID;
$hasVideo = 1;
}
}
if ( $hasVideo == 1){
$articleMedia = '<iframe class="youtube" width="100%" src="' . $articleMedia . '" frameborder="0" allowfullscreen></iframe>';
}
}
// END SEARCH IMAGE OR VIDEO
You can create a search plugin, it's very simple to to create one, especially as you've worked out your core code already.
Depending on the type of Joomla search you're using you should read either:
Creating a Search Plugin
Creating a Smart Search Plugin
In my cshtml i have defined a tag
I am creating a Image Upload Form, where On File Submit, i am saving the value in a Temp Table(SQL) and returning(GUID) the value thru a Ajax call and Binding the GUID inside Dynamically created DIV Tag(Jquery/Javascript)
<div id="dvDisplayImageParent" class="block clear" runat="server">
</div>
Now, using Javascript i am creating DIV Tags (Multiple) (Containing Images and Textbox) and appending it with dvDisplayImageParent.
I want to access the values in Controller
public ActionResult NewProject(ProjectEditViewModel model, String btnSave)
{// Want to values inside my dvDisplayImageParent }
How can i do this??
My Javascript is as follows :-
`var img = document.createElement("IMG");
var lbl = document.createElement("label");
var chk = document.createElement('input');
chk.type = 'checkbox';
//Assign image path to display the image
img.src = imgPath;
img.id = imageID;
img.style.height = "100px";
img.style.width = "100px";
//Appending it with Dynamic DIV
dynDiv.appendChild(img);
var input = document.createElement("input");
//input.setAttribute("type", "hidden");
input.setAttribute("type", "text");
input.setAttribute("name", "hdn" + imageID);
input.setAttribute("value", imageID);
//Image Link
var aElemImageLink = document.createElement('a');
//Move Up Link
var aElemUpLink = document.createElement('a');
//Move Down Link
var aElemDownLink = document.createElement('a');
var callOnImageclick = "DeleteImage('" + imageID + "','" + divDynamicID + "'); return false; ";
aElemImageLink.setAttribute("onclick", callOnImageclick);
aElemImageLink.childNodes = imageID;
var callOnMoveUpclick = "MoveImageUP('" + imageID + "','" + divDynamicID + "'); return false; ";
aElemUpLink.setAttribute("onclick", callOnMoveUpclick);
var callOnMoveDownclick = "MoveImageDOWN('" + imageID + "','" + divDynamicID + "'); return false; ";
aElemDownLink.setAttribute("onclick", callOnMoveDownclick);
//Create a text node to hold the text of the <a>
var aElemTN = document.createTextNode(' Delete Image ');
//Create a text node to hold the text of the <a>
var aElemTNUp = document.createTextNode(' Move UP ');
//Create a text node to hold the text of the <a>
var aElemTNDown = document.createTextNode(' Move DOWN ');
//Append the <a> text node to the <a> element
aElemImageLink.appendChild(aElemTN);
aElemUpLink.appendChild(aElemTNUp);
aElemDownLink.appendChild(aElemTNDown);
//Append the new link to the existing <div>
dynDiv.appendChild(aElemImageLink);
dynDiv.appendChild(aElemUpLink);
dynDiv.appendChild(aElemDownLink);
lbl.id = "lbl" + imageID;
var aElemTNTag = document.createTextNode(' Taggar ');
var aElemTNWantsToshare = document.createTextNode(' Dela? ');
var txtTag = document.createElement("input");
txtTag.id = "txt" + imageID;
txtTag.setAttribute('name', 'Tag');
dynDiv.appendChild(lbl);
dynDiv.appendChild(aElemTNTag);
dynDiv.appendChild(txtTag);
dynDiv.appendChild(chk);
dynDiv.appendChild(aElemTNWantsToshare);
dynDiv.appendChild(input);
//Appending Dynamic DIV with Parent DIV
var parentDiv = document.getElementById("dvDisplayImageParent");
parentDiv.appendChild(dynDiv);`
I Got one alternative :-
string NoOfImages = Convert.ToString(Request.Form["Your Control Name Which You Want To Access"]);
Now, using Request.Form[] use can get the value's present inside the CONTROL Created using JAVASCRIPT.
But still waiting for a better solution.
> Help Continues...
There is no runat or code behind in mvc. You can't access any elements from controller. I'd suggest watching some of these videos.