Dynamically add javascript slideshow code to header of templated site - javascript

I am working with a very outdated templated site that does not let me change anything in the top portion of the site. The Flash slideshow no longer works properly, so I was wondering if there was any way Javascript/JQuery can be added to the accessable part of the site that will dynamically replace the existing flash slideshow with a Javascript slideshow I have made?
The site is: http://www.familymattersteam.com/
Thanks in advance!

I added the following code to the "script footer" portion of the site's back end. I just started learning Javascript about a week ago, and I borrowed this code from another out of date site, so I'm sure its painful to look at. It works though!
Essentially all I did was used the innHTML command to replace the contents in the "SlideShow" ID with code for a Javascript slideshow.
var t;
var slideShowSpeed = 5000;
var crossFadeDuration = 2;
var PicA = new Array();
PicA[0] = '/Repository/1/4/1/0/7/9/141079/template_files/slide1.jpg';
PicA[01] = '/Repository/1/4/1/0/7/9/141079/template_files/slide2.jpg';
PicA[02] = '/Repository/1/4/1/0/7/9/141079/template_files/slide3.jpg';
PicA[03] = '/Repository/1/4/1/0/7/9/141079/template_files/slide4.jpg';
PicA[04] = '/Repository/1/4/1/0/7/9/141079/template_files/slide5.jpg';
var j = 0;
var p = PicA.length;
var preLoadA = new Array();
for (i = 0; i < p; i++) {
preLoadA[i] = new Image();
preLoadA[i].src = PicA[i];
};
function runSlideShowA() {
if (document.all) {
document.images.SlideShowA.style.filter='blendTrans(duration=2)';
document.images.SlideShowA.style.filter='blendTrans(duration=crossFadeDuration)';
document.images.SlideShowA.filters.blendTrans.Apply();
};
document.images.SlideShowA.src = preLoadA[j].src;
if (document.all) {
document.images.SlideShowA.filters.blendTrans.Play();
};
j = j + 1;
if (j > (p - 1)) j = 0;
t = setTimeout('runSlideShowA()', slideShowSpeed);
};
newSlide = document.getElementById('SlideShow');
newSlide.innerHTML = '<img src="/Repository/1/4/1/0/7/9/141079/template_files/slide1.jpg" name="SlideShowA" width="874" height="206">';
runSlideShowA();

Related

Randomize images when refreshing page js html

Here is a code that should render images randomly using DIV HTML rather than document.write, does anyone have an idea?
<script>
var theImages = new Array()
//Random-loading images
theImages[0] = '/img/pirc/hostnger-he.png' // replace with names of images
theImages[1] = '/img/pirc/hostnger-en.png' // replace with names of images
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
if(whichImage==0){
$('.hostnger').html('<img class="hostnger" src="'+theImages[whichImage]+'">')
}
else if(whichImage==1){
$('.hostnger').html('<img class="hostnger" src="'+theImages[whichImage]+'">')
}
}
</script>
<div class="hostnger"></div>
Randomize images when refreshing the pageenter code here
Where are you actually calling the showImage function?
You should add
showImage();
somewhere.
Are you including jQuery?
$('.hostnger')
Is a jQuery call and you are not including jQuery anywhere.

If new contact get address, subject, message

I need a program for google script that tells me if I have an email address in my contacts or not.
I get many emails from vendors each day and many of them are completely new contacts. I need a program that makes a list of only the new contacts so I can decide which contact group to add them too.
Basic structure of what I'm looking for:
Will run this program every 5 minutes (I can set that up.)
-Checks emails with yellow or blue star for email address of recipient and sender. filters out my email address.
-Checks the email address against all my contacts. If the email address does not appear in my google contacts I need:
Email address, subject line, message text, additional thread message, additional thread message... in seperate columns in a spreadsheet.
I will then go through this information manually to decide which groups to put them in.
Thank you for your help!!!
UPDATE//////////////////////////////update.3
Here's where I'm at. This is working on and off. One time I run it it works, another time it doesn't. REally annoying. If anyone can see any glairing problems let me know. Especially hard to get the if sndr and if rcpnt to return false to run the rest of the program. I've tried about 20 ways!!!
//http://webapps.stackexchange.com/questions/9813/get-e-mail-addresses-from-gmail-messages-received
/////////////NESTED LOOP METHOD
function newEmailAddressList(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("NewEmails");
var range = sheet.getRange("A2:BA");
var addrA;
range.clearContent(); //May need to change this to my delete function to speed things up.
var contact = ContactsApp.getContacts();
for(var i = 0;i < contact.length;i++){
var addrA = [];
var start;
var addresses = contact[i].getEmails();
for(var j = 0;j < addresses.length;j++){
addrA.push(addresses[j].getAddress());
};
};
sheet.getRange('H1').setValue("List Created");
for (var i=0; i<50; i++){
var threads = GmailApp.getInboxThreads(0,50)[i];
var messages = threads.getMessages()[0];
var sndr = messages.getFrom().replace(/^.+<([^>]+)>$/, "$1"); //http://stackoverflow.com/questions/26242591/is-there-a-way-to-get-the-specific-email-address-from-a-gmail-message-object-in
var rcpnt = messages.getTo().replace(/^.+<([^>]+)>$/, "$1");
function contains(addrA, sndr) {
for (var i = 0; i < addrA.length; i++) {
if (addrA[i] === sndr) {
sheet.appendRow("Emails Match");
}else{
var dat = messages.getDate();
//var sndr = messages.getFrom();
//var rcpnt = messages.getTo();
var sub = messages.getSubject();
var msg = messages.getPlainBody();
var info = [dat,sndr,rcpnt,sub,msg];
sheet.appendRow(info); //appendRow only works with sheet class not range class
};
};
};
};
};
Well, I'll give you a start. And keep in my that I've never really worked with GmailApp in the past so all of this information is pretty much readily available to any who opens the code editor clicks on help and then clicks on API Reference. Everything you need to know about Google Scripts is right there organized about as well as it's ever been. They have really improved their documentation since the first time I've looked at it several years ago.
So I'm giving you some functions that will get all of your contact emails, your from emails from your inbox and and your emails.
function myContacts()
{
var s = '';
var br = '<br />';
var contact = ContactsApp.getContacts();
for(var i = 0;i < contact.length;i++)
{
var addrA = [];
var addresses = contact[i].getEmails();
for(var j = 0;j < addresses.length;j++)
{
s += addresses[j].getAddress() + br;
addrA.push(addresses[j].getAddress());
}
}
dispStatus('Contact Emails',s, 800, 400);
}
function MyFroms()
{
var threads = GmailApp.getInboxThreads();
var s = '';
for(var i = 0; i < threads.length; i++)
{
var msg = threads[i].getMessages();
for(var j = 0; j < msg.length;j++)
{
s += msg[j].getFrom() + '<br />';
}
}
dispStatus('My Messages', s , 800 , 400);
}
function MyMessages()
{
var threads = GmailApp.getInboxThreads();
var s = '';
for(var i = 0; i < threads.length; i++)
{
var msg = threads[i].getMessages();
for(var j = 0; j < msg.length;j++)
{
s += 'Message' + j+1 + '<br />';
s += msg[j].getFrom() + '<br />';
s += msg[j].getBody() + '<br />';
}
}
dispStatus('My Messages', s , 800 , 400);
}
function dispStatus(title,html,width,height)
{
var title = typeof(title) !== 'undefined' ? title : 'No Title Provided';
var width = typeof(width) !== 'undefined' ? width : 800;
var height = typeof(height) !== 'undefined' ? height : 400;
var html = typeof(html) !== 'undefined' ? html : '<p>No html provided.</p>';
var htmlOutput = HtmlService
.createHtmlOutput(html)
.setWidth(width)
.setHeight(height);
SpreadsheetApp.getUi().showModelessDialog(htmlOutput, title);
}
It's not a complete answer. But hopefully it will encourage you to jump in get your feet wet and exercise your mental muscles and bring us back at least a partially working skeleton of a program that we can help you get running.

change HTML code for fading background replacing images

This is my HTML code:
<html>
<head>
<script language="JavaScript">
<!--
// Set speed (milliseconds)
var speed = 4000
// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below
Pic[0] = 'img_1.jpg'
Pic[1] = 'img_2.jpg'
Pic[2] = 'img_3.jpg'
Pic[3] = 'img_4.jpg'
// =======================================
// do not edit anything below this line
// =======================================
var t
var j = 0
var p = Pic.length
var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]
}
function runBGSlideShow(){
if (document.body){
document.body.background = Pic[j];
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runBGSlideShow()', speed)
}
}
//-->
</script>
</head>
<body onload="runBGSlideShow()">
</body>
</html>
I tried everything I know to change it so the pictures will fade when replacing but I didn't succeed.
If you can I will appreciate it if you will add to the HTML code (if can't it's ok to add css )
Please look and see if you can help me.
Why reinvent the wheel?
There's a beautiful jQuery plugin that does this already
http://srobbin.com/jquery-plugins/backstretch/

JavaScript createElement Line Causes Error

I'm writing a simple JavaScript program to examine every element in an HTML website and add a child node to every non-text node that labels the type of tag:
Here is my code:
window.onload = function() {
var body_elems = document.body.getElementsByTagName("*");
for (var i = 0; i < body_elems.length; i++) {
if (body_elems[i].nodeType != 3) {
var tag_name = body_elems[i].tagName;
var child = document.createElement("P");
var child_text = document.createTextNode(tag_name);
child.appendChild(child_text);
body_elems[i].appendChild(child);
body_elems[i].firstChild.className = "hoverNode";
}
}
}
For some reason the line var child = document.createElement("P") causes the page to never load; if I comment out that line then the page will load.
On the other hand, here is a slightly different version that actually works:
window.onload = function() {
var body_elems = document.body.getElementsByTagName("*");
for (var i = 0; i < body_elems.length; i++) {
if (body_elems[i].nodeType != 3) {
var tag_name = body_elems[i].tagName;
var child = document.createTextNode(tag_name);
body_elems[i].appendChild(child);
child.className="hoverNode";
}
}
}
But I can't figure out how to assign a class name to the new node in order to apply CSS, so if someone could tell me how to do that my problem would be solved.
I'm new to JS so any help would be much appreciated.

Change Firefox Bookmarks To TitleCase (Capitalize Each Word)

This My First Question Hear In Stack Overflow, And I Wish To Get The Help I Expect..
I Was Looking For A Way To Change All The Firefox Bookmarks Titles
To 'TitleCase' .
I've already found a perfect technique to change it to UPPERCase using a fierfox Dev. tool
called "scratchpad" in the browser environment .
here's the steps for it:-
open about:config
set devtools.chrome.enabled to true
tools > web developer > scratchpad
environment > browser
edit > paste (i.e. copy and paste code below)
execute > run
Code.
function getChildIds(aRootNode, aChildIds) {
for (var i = 0; i < aRootNode.childCount; i++) {
var node = aRootNode.getChild(i);
aChildIds.push(node.itemId);
if (node.type == node.RESULT_TYPE_FOLDER) {
node.QueryInterface(Ci.nsINavHistoryContainerResultNode);
var oldContainerOpen = node.containerOpen;
node.containerOpen = true;
getChildIds(node, aChildIds);
node.containerOpen = oldContainerOpen;
}
}
}
var bs = Cc["#mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var hs = Cc["#mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var query = hs.getNewQuery();
var options = hs.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_BOOKMARKS;
var folders = new Array();
folders.push(bs.bookmarksMenuFolder); // Bookmarks Menu
folders.push(bs.toolbarFolder); // Bookmarks Toolbar
folders.push(bs.unfiledBookmarksFolder); // Unsorted Bookmarks
var childIds = new Array();
for (var i = 0; i < folders.length; i++) {
query.setFolders(folders.slice(i, i + 1), 1);
var result = hs.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
getChildIds(rootNode, childIds); // recursive function
rootNode.containerOpen = false;
}
bs.runInBatchMode({
runBatched: function () {
for (var i = 0; i < childIds.length; i++) {
var type = bs.getItemType(childIds[i]);
if (type == bs.TYPE_BOOKMARK || type == bs.TYPE_FOLDER) {
var title = bs.getItemTitle(childIds[i]);
if (title) {
bs.setItemTitle(childIds[i], title.toUpperCase());
}
}
}
}
}, null);
So, My Question Is, How To Modify That Code In Order To Change The Bookkmarks' Titles
To TitleCase (Capitalize Each Word) ?
Thanks In Advance...
See this website:
http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase(v=vs.110).aspx
You can use the method ToTitleCase from the TextInfo class to change a string to title case. (Make sure that the title variable is a string.) Then, instead of using title.toUpperCase use title.ToTitleCase.
I hope this helps,
Santiago

Categories

Resources