Skip to content

Instantly share code, notes, and snippets.

@AstDerek
Created September 20, 2012 21:52
Show Gist options
  • Save AstDerek/3758576 to your computer and use it in GitHub Desktop.
Save AstDerek/3758576 to your computer and use it in GitHub Desktop.
Remodelación de Moodle/FCA en Línea
// ==UserScript==
// @name FCA en linea
// @namespace fca_en_linea
// @include http://fcaenlinea1.unam.mx/informatica/escritorio/
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @version 1
// @grant none
// ==/UserScript==
/**
function loadScript (scriptURL) {
var scriptElem = document.createElement('SCRIPT');
scriptElem.setAttribute('language', 'JavaScript');
scriptElem.setAttribute('src', scriptURL);
document.body.appendChild(scriptElem);
}
loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
*/
jQuery.noConflict();
var $ = function (selector, context) {
if (selector === undefined && context === undefined) {
return jQuery();
}
else if (context === undefined) {
return jQuery(selector,window.frames[1].document);
}
return jQuery(selector,context);
}
jQuery.extend($,jQuery);
$.ready = function (context) {
var interval = setInterval(function(){
},500);
};
function rebuild (data){
var wrapper = '',
messages = '',
content = '',
profile = '';
$("frameset, noframes").remove();
if ($("body").length===0) {
$("html").append(
document.createElement("body")
);
}
$("body").html(
data.replace(/^[\s\S]*<body[^>]*>([\s\S]*?)<\/body[\s\S]*$/ig,'$1') +
"<style>" +
".hidden {" +
"display:none;" +
"}" +
".clear {" +
"clear:both;" +
"}" +
".round-border {" +
"border: 1px solid #ccc;" +
"background: #fff;" +
"-moz-border-radius: 6px;" +
"-webkit-border-radius: 6px;" +
"-o-border-radius: 6px;" +
"border-radius: 6px;" +
"-moz-box-shadow: 3px 3px 3px #ccc;" +
"-webkit-box-shadow: 3px 3px 3px #ccc;" +
"-o-box-shadow: 3px 3px 3px #ccc;" +
"box-shadow: 3px 3px 3px #ccc;" +
"position: relative;" +
"}" +
".name a {" +
"font-size:1.2em;" +
"line-height:1.2em;" +
"}" +
"</style>"
);
wrapper = $("#content");
messages = $("#left-column").contents().detach();
content = $("#middle-column").contents().detach();
profile = $("#right-column").contents().detach();
wrapper.css({
padding: '1em'
});
messages.css({
position: 'absolute',
top: 0,
left: 0
});
profile.css({
position: 'absolute',
top: 0,
right: 0
});
$("#layout-table").remove();
$("#content")
.append(content)
.append('<div id="ajax-data" />')
//.append(messages)
//.append(profile);
$(".sitetopic").children().wrapAll("<div />");
$(".sitetopic")
.addClass("round-border")
.prepend('<a href="#" style="position:absolute;top:0;right:0;display:inline-block;width:1.5em;height:1.5em;">^</a>');
$(".sitetopic a:first").click(function(e){
e.preventDefault();
var $this = $(this),
div = $this.parent().find("div:first");
if (div.is(":visible")) {
div.slideUp();
$this.text("v");
}
else {
div.slideDown();
$this.text("^");
}
return false;
});
$(".coursebox br").remove();
$(".coursebox .info").append(
'<p class="menu hidden">' +
'<a href="#return" class="navigation" title="Mostrar lista de asignaturas">[«]</a> | ' +
'<a href="#carpeta.html" class="navigation">Calificaciones</a> | ' +
'<a href="#foro.html" class="navigation">Foro</a> | ' +
'<a href="#chat.html" class="navigation">Chat</a> | ' +
'<a href="#comunidad.html" class="navigation">Comunidad</a> | ' +
'<a href="#asesor.html" class="navigation">Asesor</a>' +
'</p>'
);
$(".coursebox .summary").append(
'<p class="menu hidden">' +
'<a href="#introduccion.html" class="navigation">Inicio</a> | ' +
'<a href="#objetivo.html" class="navigation">Objetivos</a> | ' +
'<a href="#estruc_concpt.html" class="navigation">Estructura Conceptual</a> | ' +
'<a href="#unidades.html" class="navigation">Unidades</a> | ' +
'<a href="#plan.html" class="navigation">Plan de Trabajo</a> | ' +
'<a href="#glosario_gral.html" class="navigation">Glosario</a> | ' +
'<a href="#examen.html" class="navigation">Examen Final</a>' +
'</p>'
);
$(".coursebox .summary").after('<div class="clear" />');
$(".coursebox p a.navigation").click(function(e){
e.preventDefault();
var $this = $(this),
href = $this.closest(".coursebox").find(".name a").data("href");
//$("iframe").attr("src",href + $this.attr("href").substr(1));
$.ajax({
url: href + $this.attr("href").substr(1),
success: function(data){
$("#ajax-data").html(
data
.replace(/^[\s\S]*?<body[^>]*>/ig,'')
.replace(/<\/body[\s\S]*$/ig,'')
.replace(/(src|href)="http/ig,'$1="/http')
.replace(/(src|href)="([^\/])/ig,'$1="' + href + '$2')
.replace(/(src|href)="\/http/ig,'$1="http')
.replace(/width="500%"/ig,'width="100%"')
);
}
});
return false;
});
$("#content .unlist li").each(function(){
var $this = $(this);
$this.css('display','block');
//$this.height($this.height() + 5);
//$this.width($this.width());
$this.width('100%');
});
$(".coursebox .info .name a").each(function(){
$(this).click(function(e){
e.preventDefault();
var $this = $(this),
li = $this.closest("li"),
href = $this.data("href"),
iframe = $("iframe"),
interval = false;
$("a").attr("disabled","");
$("#content .unlist li")
.not(li).slideUp()
.find("p").slideUp();
li.find("p").slideDown();
if (!href && !interval) {
if (!iframe.length) {
$("#content").prepend('<iframe width="100" height="100" style="float:left;display:none;" src="' + $this.attr("href") + '"/>');
iframe = $("iframe");
}
else {
iframe.attr("src",$this.attr("href"));
}
interval = setInterval(function(){
// http://fcaenlinea1.unam.mx/informatica/file.php/55/soporte_tecnico_02/index.html
if (window.frames[1].frames[0].document.readyState !== "complete") {
return;
}
clearInterval(interval);
interval = false;
$("a").removeAttr("disabled");
href = window.frames[1].frames[0].location.href.replace('index.html','');
$this.data("href",href);
},500);
}
return false;
});
});
$(".coursebox a[href$=return]").click(function(e){
e.preventDefault();
$("#content .unlist li:not(:visible)").slideDown();
$("#content .unlist li p:visible").slideUp();
$("#ajax-data").html("");
return false;
});
}
jQuery("frameset").attr("rows","0,*,0");
jQuery("frame").removeAttr("scrolling");
$.ajax({
url:'/informatica/',
success:rebuild
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment